[Twisted-Python] Making inlineCallback return a generator rather than a Deferred
Andrew Francis
andrewfr_ice at yahoo.com
Sat Jan 26 13:21:45 MST 2008
Hello Folks:
As I previously mentioned, I have the following called
from a PyAMF method:
@defer.inlineCallbacks
def echo(self, x):
result = yield client.getPage("http://localhost")
because of the yield, I cannot use
return result
In a bout of wishful thinking, I tried the following:
@defer.inlineCallbacks
def __echo__(self, x):
result = yield client.getPage("http://localhost")
yield result
def echo(self, x):
return self.__echo__(x).next()
This raises an AttributeError, the deferred does not
have an attribute next() (this is because the deferred
is well, a deferred)
Again, perhaps I am missing something obvious. Or
perhaps this scenario was not anticipated and syntax
is getting in the way. However I think the following
would be useful in these situations
def echo(self, x)
@defer.returnAGenerator
def __echo__(x):
result = yield client.getPage("...")
yield result
"""
the method waits until there is a result
"""
return __echo__(x).next()
and the wrapper (i.e., PyAMF, xmlrpc, etc) is happy.
I started to look at defer.inlineCallbacks and its
associated methods, such as and _inlineCallbacks,
unwindGenerator, and mergeFunctionMetadata.
I would like to know if it would make sense to just
return a generator and have it behave the way I want.
If so, what exactly do I have to do in some variation
of _inlineCallbacks to make this so?
Thanks,
Andrew
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
More information about the Twisted-Python
mailing list