[Twisted-Python] Amazing exception "GeneratorExit"

Hi all, i got strange error If run this: # -*- coding: UTF-8 -*- import os import sys from twisted.python import log from twisted.internet import reactor from twisted.internet.defer import Deferred, inlineCallbacks @inlineCallbacks def _(): try: (yield Deferred()) except: log.err() reactor.callLater(0, _) reactor.run() i got exception "GeneratorExit" Why?! ... this code work: # -*- coding: UTF-8 -*- import os import sys from twisted.python import log from twisted.internet import reactor from twisted.internet.defer import Deferred, inlineCallbacks @inlineCallbacks def _(): deferred = Deferred() try: (yield deferred) except: log.err() reactor.callLater(0, _) reactor.run() Change "Deferred()" to "deferred = Deferred()"

On Fri, Jan 25, 2013 at 10:35 AM, Аркадий Левин <poisonoff@gmail.com> wrote:
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. http://docs.python.org/2.7/reference/expressions.html?highlight=yield%20expr... See the stuff about how .close() throws GeneratorExit into the generator. 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?) -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/

On Fri, Jan 25, 2013 at 10:35 AM, Аркадий Левин <poisonoff@gmail.com> wrote:
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. http://docs.python.org/2.7/reference/expressions.html?highlight=yield%20expr... See the stuff about how .close() throws GeneratorExit into the generator. 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?) -- Christopher Armstrong http://radix.twistedmatrix.com/ http://planet-if.com/
participants (2)
-
Christopher Armstrong
-
Аркадий Левин