[Twisted-Python] Making inlineCallback return a generator rather than a Deferred

Tristan Seligmann mithrandi at mithrandi.za.net
Sat Jan 26 16:28:34 EST 2008

* Andrew Francis <andrewfr_ice at yahoo.com> [2008-01-26 12:21:45 -0800]:

> 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.

This is essentially impossible to implement; you need some way to
suspend the code that is invoking the generator, and there isn't any
general way to this in Python. There is nothing magical about the
.next() method on a generator, it is just a normal synchronous function
mithrandi, i Ainil en-Balandor, a faer Ambar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20080126/89ff60a0/attachment.pgp 

More information about the Twisted-Python mailing list