[Twisted-Python] How to show traceback of "Unhandled error"?

Jason Litzinger jlitzingerdev at gmail.com
Fri May 18 22:37:51 MDT 2018


> Try this:
> 
> 
> from twisted.logger import globalLogBeginner, textFileLogObserver
> from twisted.internet.defer import Deferred
> import sys
> 
> globalLogBeginner.beginLoggingTo([textFileLogObserver(sys.stdout)])
> 
> def raiseErr(what):
>     raise Exception(what)
> 
> d = Deferred()
> d.addCallback(raiseErr)
> d.callback("asdf")
FWIW, I had some trouble (nothing printed) with Python 3.6 using the
example above.  Python 2 was fine, and PYTHONUNBUFFERED (or flush) didn't help.
I'll follow up should I figure out what's going on.  I had success on
Python3 with the STDLibLogObserver...which doesn't make any immediate
sense other than something flushing related.
> 
> 
> 
> https://twistedmatrix.com/trac/ticket/9333
> 
> The associated PR needs a careful review to ensure its handling of unicode is correct.  Any takers?
Agree, given the recent tickets/regressions related to Unicode I'm going
to go back through my PR.  If it disappears from review...I found
something.
> > 
> > # how to show the traceback without manually adding an errback at the end?
> > # adding at the *end* of a deferred is hard as we don't know when the
> > client stops adding callbacks.
I've also found this advice from Jean-Paul very helpful:
https://twistedmatrix.com/pipermail/twisted-python/2018-March/031856.html

You'll get more detailed info:
CRITICAL:twisted:Unhandled error in Deferred:
CRITICAL:twisted:(debug:  C: Deferred was created:
 C:  File "foo.py", line 15, in <module>
 C:    d = defer.Deferred()
 I: First Invoker was:
 I:  File "foo.py", line 17, in <module>
 I:    d.callback("asdf")
)
Traceback (most recent call last):
  File "/home/jlitzing/dev/twisted/twisted-fork/src/twisted/internet/defer.py", line 653, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "foo.py", line 13, in raiseErr
    raise Exception(what)
Exception: asdf

Cheers,
-Jason



More information about the Twisted-Python mailing list