<br><br><div class="gmail_quote">On Tue, Apr 10, 2012 at 12:50 PM, Andrew Bennetts <span dir="ltr"><<a href="mailto:andrew@bemusement.org">andrew@bemusement.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Apr 10, 2012 at 12:41:17PM +0800, gelin yan wrote:<br>
[…]<br>
<div class="im">> When trying to run inlineCallbacks with Cython, a TypeError would come<br>
> out like:<br>
><br>
> TypeError: inlineCallbacks requires <built-in function test> to produce a<br>
> generator; instead got <cy3.__pyx_scope_struct__test object at 0x02808848)<br>
><br>
> test is the function where inlineCallbacks uses.<br>
><br>
> It looks like cython changes the name test to cy3.__pyx_scope_struct__test<br>
> internally so generator can't work properly.<br>
<br>
</div>inlineCallbacks doesn't care what the function name is. The problem here is<br>
that inlineCallbacks expects to be passed a generator function[1], and instead<br>
it is being passed some other sort of object. The ugly cy3.__blah name is a red<br>
herring.<br>
<br>
-Andrew.<br>
<br>
[1] Without the check that produces this error, a common and very confusing<br>
error is to decorate a non-generator function (i.e. one with no yield<br>
statement) with @inlineCallbacks, which would appear to work but would then<br>
mysteriously fail to do anything useful when executed.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a></div></div></blockquote><div><br></div><div>Hi Andrew</div><div>
Thanks for replying. the yield was actually there: test function is:</div><div><br></div><div><div>def await(seconds):</div><div> d = defer.Deferred()</div><div> reactor.callLater(seconds, d.callback, True)</div>
<div> return d</div></div><div><br></div><div><div>@defer.inlineCallbacks</div><div>def test():</div><div> thing = yield await(2)</div><div> print "hey"</div></div><div><br></div><div> Do you have any idea how to work around? Thanks</div>
<div><br></div><div>Regards</div><div><br></div><div>gelin yan</div><div><br></div><div> </div><div><br></div><div> </div></div><br>