[Twisted-Python] Try/catching yielded Exceptions and getting proper tracebacks

Terry Jones terry at jon.es
Mon Feb 22 09:36:24 EST 2010

Hi Paul

>>>>> "Paul" == Paul Goins <general at vultaire.net> writes:

You're only printing the exception, not a full traceback, so you don't see
much. I tend to write what you're doing as follows:

    from twisted.python import log

    def xmlrpc_dosomething(self):
        d = self._do_something_else()
        result = yield d

If you try that you'll see a full traceback. The above lets log.err handle
the failure that comes back via the errback on the deferred you get from
_do_something_else, and log.err knows how to get the full traceback.

I don't know if it's clear, but whenever you call an inlineCallbacks
decorated method/func, you get a deferred back (unless you happen to
mistakenly use inlineCallbacks to decorate something that's not a
generator). You can add errbacks to that deferred, just like any other, and
if you're making the call from inside another inlineCallbacks decorated
function, you can just do as above: add call/errbacks to the deferred, and
then yield it.


More information about the Twisted-Python mailing list