<br><div class="gmail_quote">On Mon, Jul 16, 2012 at 11:20 PM, Andrew Bennetts <span dir="ltr"><<a href="mailto:andrew@bemusement.org" target="_blank">andrew@bemusement.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dan Stromberg wrote:<br>
[…]<br>
<div class="im">> I'm playing with twisted.internet.defer.setDebugging now.<br>
><br>
> Is there a corresponding function that can be used to produce its report?<br>
> If I use it in a program with an infinite loop, it seems like I never get<br>
> the report, but if I use it in a program with a finite length, I eventually<br>
> get a useful-looking report.<br>
<br>
</div>It's triggered by garbage collection of a Deferred with an unhandled error. So<br>
you're at the mercy of when the garbage collector of your Python VM decides to<br>
collect that object.<br>
<br>
You could call yourDeferred._debugInfo._getDebugTracebacks() yourself, though,<br>
if you don't mind (ab)using private attributes that might break without warning.</blockquote><div><br>Strangely, this doesn't give the report until after the sleep finishes... ?<br><br>#!/usr/bin/python<br><br>
# deferreds work fine without the reactor<br><br>import time<br><br>import twisted.internet.defer<br><br>twisted.internet.defer.setDebugging(True)<br><br>def functionReturningDeferred():<br> return twisted.internet.defer.succeed('Some value')<br>
<br>d = functionReturningDeferred()<br>def printValue(value):<br> print 'Yay, I got %r' % value<br> return value<br>def second_callback(value):<br> print 'still %r' % value<br> return gen_error()<br>
def third_callback(value):<br> print 'and still %r' % value<br> #raise AssertionError<br> return value<br><br>def gen_error():<br> return twisted.internet.defer.fail(AssertionError)<br><br><br>def got_error(value):<br>
print 'bad thing: %r' % value<br><br>d.addCallback(printValue)<br>d.addCallback(second_callback)<br>d.addCallback(third_callback)<br>d._debugInfo._getDebugTracebacks()<br>print<br>time.sleep(10)<br>#d.addErrback(got_error)<br>
<br><br></div></div>