[Twisted-Python] Amazing exception "GeneratorExit"
radix at twistedmatrix.com
Fri Jan 25 12:49:09 EST 2013
On Fri, Jan 25, 2013 at 10:35 AM, Аркадий Левин <poisonoff at gmail.com> wrote:
> 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
> def _():
> (yield Deferred())
> reactor.callLater(0, _)
> i got exception "GeneratorExit" Why?!
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.
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?)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python