<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Fri, Jan 25, 2013 at 10:35 AM, Аркадий Левин <span dir="ltr"><<a href="mailto:poisonoff@gmail.com" target="_blank">poisonoff@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all, i got strange error<br>
<br>
If run this:<br>
<br>
# -*- coding: UTF-8 -*-<br>
<br>
import os<br>
import sys<br>
<br>
from twisted.python import log<br>
from twisted.internet import reactor<br>
from twisted.internet.defer import Deferred, inlineCallbacks<br>
<br>
@inlineCallbacks<br>
def _():<br>
<br>
try:<br>
(yield Deferred())<br>
except:<br>
log.err()<br>
<br>
reactor.callLater(0, _)<br>
reactor.run()<br>
<br>
i got exception "GeneratorExit" Why?!<br></blockquote><div><br></div><div><br></div><div style>This behavior isn't specific to inlineCallbacks. If you get rid of the reactor usage and the @inlineCallbacks decorator, and just call _().next(), you'll see the same behavior.</div>
<div style><br></div><div style><a href="http://docs.python.org/2.7/reference/expressions.html?highlight=yield%20expression#generator-iterator-methods">http://docs.python.org/2.7/reference/expressions.html?highlight=yield%20expression#generator-iterator-methods</a><br>
</div><div style><br></div><div style>See the stuff about how .close() throws GeneratorExit into the generator.</div><div style><br></div><div style>It is related to garbage collection. When a generator is garbage collected, its .close() method is called. Since you're keeping a reference to the Deferred in the generator itself in the working version, it's not being immediately closed because there's a circular reference. (I think?)</div>
</div><div><br></div>-- <br>Christopher Armstrong<br><a href="http://radix.twistedmatrix.com/">http://radix.twistedmatrix.com/</a><br><a href="http://planet-if.com/">http://planet-if.com/</a><br><br>
</div></div>