[Twisted-Python] Gc of deferreds

Christopher Armstrong radix at twistedmatrix.com
Tue Jul 8 16:34:15 EDT 2008

On Tue, Jul 8, 2008 at 4:11 PM, Rutt, Benjamin <Benjamin.Rutt at gs.com> wrote:
> #!/usr/bin/env python
> from twisted.internet import defer,reactor,utils
> def foo():
>    d = utils.getProcessOutput('sleep', args=['2'])
>    def cb(data):
>      print "cb fired"
>      return data
>    d.addCallback(cb)
>    return d
> foo()
> reactor.callLater(5, reactor.stop)
> reactor.run()
> Yet when I run it, it seems everything works fine:
> $ ./spawner.py
> cb fired
> $

getProcessOutput will cause a reference to be held to it. It needs
that reference so it can fire the deferred once the process is

> I am just questioning the need to keep deferreds in memory somewhere, if
> they haven't fired their callbacks yet.  Thanks.

Um, how will their callbacks be fired if they're not in memory any more?

Christopher Armstrong
International Man of Twistery

More information about the Twisted-Python mailing list