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

gelin yan dynamicgl at gmail.com
Mon Apr 9 23:33:49 MDT 2012


On Tue, Apr 10, 2012 at 12:50 PM, Andrew Bennetts <andrew at bemusement.org>wrote:

> On Tue, Apr 10, 2012 at 12:41:17PM +0800, gelin yan wrote:
> […]
> >     When trying to run inlineCallbacks with Cython, a TypeError would
> come
> > out like:
> >
> > TypeError: inlineCallbacks requires <built-in function test> to produce a
> > generator; instead got <cy3.__pyx_scope_struct__test object at
> 0x02808848)
> >
> > test is the function where inlineCallbacks uses.
> >
> > It looks like cython changes the name test to
>  cy3.__pyx_scope_struct__test
> > internally so generator can't work properly.
>
> inlineCallbacks doesn't care what the function name is.  The problem here
> is
> that inlineCallbacks expects to be passed a generator function[1], and
> instead
> it is being passed some other sort of object.  The ugly cy3.__blah name is
> a red
> herring.
>
> -Andrew.
>
> [1] Without the check that produces this error, a common and very confusing
>    error is to decorate a non-generator function (i.e. one with no yield
>    statement) with @inlineCallbacks, which would appear to work but would
> then
>    mysteriously fail to do anything useful when executed.
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>

Hi Andrew
   Thanks for replying. the yield was actually there:  test function is:

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

@defer.inlineCallbacks
def test():
   thing = yield await(2)
   print "hey"

  Do you have any idea how to work around? Thanks

Regards

gelin yan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20120410/80145eeb/attachment.html>


More information about the Twisted-Python mailing list