[Twisted-Python] deferred graph?

Tom Prince tom.prince at ualberta.net
Wed Jul 18 23:04:13 EDT 2012

Dan Stromberg <drsalists at gmail.com> writes:
> Strangely, this doesn't give the report until after the sleep finishes...

That is because the code you included doesn't actually print the
returned traceback. The reason that it gets printed at the end is
because it gets garbage collected then.

The following code prints out the traceback twice, with the first before
the first sleep and the second (prefixed with "Unhandled error in
Deferred:") before the second sleep.



import time
from twisted.internet import defer


def functionReturningDeferred():
    return defer.succeed('Some value')

d = functionReturningDeferred()
def printValue(value):
    print 'Yay, I got %r' % value
    return value
def second_callback(value):
    print 'still %r' % value
    return gen_error()
def third_callback(value):
    print 'and still %r' % value
    return value

def gen_error():
    return defer.fail(AssertionError)

def got_error(value):
    print 'bad thing: %r' % value

print d._debugInfo._getDebugTracebacks()
del d

More information about the Twisted-Python mailing list