[Twisted-Python] deferred graph?

Dan Stromberg drsalists at gmail.com
Mon Jul 16 19:45:46 EDT 2012


On Mon, Jul 16, 2012 at 11:20 PM, Andrew Bennetts <andrew at bemusement.org>wrote:

> Dan Stromberg wrote:
> […]
> > I'm playing with twisted.internet.defer.setDebugging now.
> >
> > Is there a corresponding function that can be used to produce its report?
> > If I use it in a program with an infinite loop, it seems like I never get
> > the report, but if I use it in a program with a finite length, I
> eventually
> > get a useful-looking report.
>
> It's triggered by garbage collection of a Deferred with an unhandled
> error.  So
> you're at the mercy of when the garbage collector of your Python VM
> decides to
> collect that object.
>
> You could call yourDeferred._debugInfo._getDebugTracebacks() yourself,
> though,
> if you don't mind (ab)using private attributes that might break without
> warning.


Strangely, this doesn't give the report until after the sleep finishes...
?

#!/usr/bin/python

# deferreds work fine without the reactor

import time

import twisted.internet.defer

twisted.internet.defer.setDebugging(True)

def functionReturningDeferred():
    return twisted.internet.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
    #raise AssertionError
    return value

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


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

d.addCallback(printValue)
d.addCallback(second_callback)
d.addCallback(third_callback)
d._debugInfo._getDebugTracebacks()
print
time.sleep(10)
#d.addErrback(got_error)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120716/10489572/attachment-0001.htm 


More information about the Twisted-Python mailing list