[Twisted-Python] lost tracebacks?

Alec Flett alecf at metaweb.com
Wed Dec 10 15:42:06 EST 2008

Ah, I found the problem, for anyone else who runs into this...

I am collecting stacks using the logging system's addObserver() -  
trying to access the traceback from a garbage-collected deferred.  
Turns out when the deferred is garbage collected, the failure is  
pickled (to avoid leaks) and so it sets failure.tb to None.

By the time you get it in your log observer and store it for later,  
you can't re-raise the exception with the stack. but  
failure.getTraceback() gave me enough stack to at least debug.

I was hoping for a "real" traceback because Paste's EvalException  
middleware does a nice job debugging "live" stacks, but the 'verbose'  
stack is a pretty decent stand-in.


On Dec 9, 2008, at 5:29 PM, glyph at divmod.com wrote:

> On 12:41 am, alecf at metaweb.com wrote:
>> I traced this down to the code in Deferred._runCallbacks() which  
>> does a try: / except: with::
>>    self.result = failure.Failure()
>> Seems like this code should say::
>>    exc_type, exc_value, exc_traceback = sys.exc_info()
>>    self.result = failure.Failure(exc_value, exc_type, exc_traceback)
> Those are basically equivalent.  Observe:
>>>> from twisted.python.failure import Failure
>>>> try:
> ...  1/0
> ... except:
> ...  f = Failure()
> ...
>>>> f.printTraceback()
> Traceback (most recent call last):
> --- <exception caught here> ---
> File "<stdin>", line 2, in <module>
> exceptions.ZeroDivisionError: integer division or modulo by zero
> Note how it remembers the line number in the traceback.  Your  
> traceback must be getting lost for some other reason.
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list