[Twisted-Python] defer.inlineCallbacks dosn't work with cython, deferredGenerator does.

gelin yan dynamicgl at gmail.com
Mon Apr 9 04:05:41 MDT 2012


Hi All

   I just to let you know that defer.inlineCallbacks can't work with cython
well. an example:


def await():
   d = defer.Deferred()
   reactor.callLater(3, d.callback, True)
   return d

@defer.inlineCallbacks
def host():
   thing = yield await()
   ""do sth"""

will fail to work on cython due to cython would change the function
name(here I refer to host()) which lead to generator can't send back the
result to the original function.

However, deferredGenerator does work with cython

like:

@defer.deferredGenerator
def host():
    d = await()
    thing = defer.waitForDeferred(d)
    yield thing


  It is not a common case to write such codes with cython, in case of need,
deferredGenerator may help.

 I personally hope deferredGenerator will be always there even python 2.4
support has been abandoned. deferredGenerator itself is not so elegant as
inlineCallbacks, at least I don't need

to struggle with a series of callback functions..

Regards

gelin yan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20120409/cf1f658e/attachment-0001.html>


More information about the Twisted-Python mailing list