<br><br><div class="gmail_quote">On Tue, Apr 10, 2012 at 1:32 PM, Glyph Lefkowitz <span dir="ltr">&lt;<a href="mailto:glyph@twistedmatrix.com">glyph@twistedmatrix.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
On Apr 9, 2012, at 9:50 PM, Andrew Bennetts wrote:<br>
<br>
&gt; On Tue, Apr 10, 2012 at 12:41:17PM +0800, gelin yan wrote:<br>
&gt; […]<br>
&gt;&gt;    When trying to run inlineCallbacks with Cython, a TypeError would come<br>
&gt;&gt; out like:<br>
&gt;&gt;<br>
&gt;&gt; TypeError: inlineCallbacks requires &lt;built-in function test&gt; to produce a<br>
&gt;&gt; generator; instead got &lt;cy3.__pyx_scope_struct__test object at 0x02808848)<br>
&gt;&gt;<br>
&gt;&gt; test is the function where inlineCallbacks uses.<br>
&gt;&gt;<br>
&gt;&gt; It looks like cython changes the name test to  cy3.__pyx_scope_struct__test<br>
&gt;&gt; internally so generator can&#39;t work properly.<br>
&gt;<br>
&gt; inlineCallbacks doesn&#39;t care what the function name is.  The problem here is<br>
&gt; that inlineCallbacks expects to be passed a generator function[1], and instead<br>
&gt; it is being passed some other sort of object.  The ugly cy3.__blah name is a red<br>
&gt; herring.<br>
&gt;<br>
&gt; -Andrew.<br>
&gt;<br>
&gt; [1] Without the check that produces this error, a common and very confusing<br>
&gt;    error is to decorate a non-generator function (i.e. one with no yield<br>
&gt;    statement) with @inlineCallbacks, which would appear to work but would then<br>
&gt;    mysteriously fail to do anything useful when executed.<br>
<br>
</div>Aah, I see.  So Twisted&#39;s check is a bit overzealous in the context of Cython.<br>
<br>
Could you perhaps wrap the Cython pseudo-generator in a function that converts it into something like a real Python generator, or disable the warning and see if it works as expected?  PEP 380 &lt;<a href="http://www.python.org/dev/peps/pep-0380/" target="_blank">http://www.python.org/dev/peps/pep-0380/</a>&gt; does have some code which one might use to do general-purpose iterator-to-generator conversion.<br>

<br>
In any case, please file a bug.  Search the tracker for duplicates first, of course, but there don&#39;t appear to be any.  There is some precedent for fixing this type of error, too: &lt;<a href="http://twistedmatrix.com/trac/ticket/3132" target="_blank">http://twistedmatrix.com/trac/ticket/3132</a>&gt; was somewhat similar.<br>

<span class="HOEnZb"><font color="#888888"><br>
-glyph<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<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><br>
</div></div></blockquote></div><br><div><br></div><div>Hi</div><div><br></div><div>   I come up with a link about this problem</div><div><a href="http://groups.google.com/group/cython-users/browse_thread/thread/295937ae99fdfebe/9b0872a76e0172d8#9b0872a76e0172d8">http://groups.google.com/group/cython-users/browse_thread/thread/295937ae99fdfebe/9b0872a76e0172d8#9b0872a76e0172d8</a>
</div><div><br></div><div>feel free to check it. Thanks</div><div><br></div><div>Roughly, It can be concluded that cython has a different generator implementation so that it can&#39;t work well with inlinecallback</div><div>
<br></div><div>Regards</div><div><br></div><div>gelin yan</div>