[Twisted-Python] Understanding deferred and error handling
David
david at silveregg.co.jp
Thu Apr 21 20:53:35 EDT 2011
On 04/21/2011 10:12 AM, exarkun at twistedmatrix.com wrote:
> log.err takes an additional argument which you can use easily like this:
>
> def main():
> d = remote_call()
> d.addErrback(log.err, "remote_call failed")
> def _stop(ignored):
> reactor.stop()
> d.addCallback(_stop)
>
> The message you pass here will replace the "Unhandled error in Deferred"
> text in the report of the failure.
ok, thanks for the tip.
>
> Another option is to enable Deferred debugging, which I think someone
> mentioned earlier in the thread:
>
> from twisted.internet.defer import setDebugging
> setDebugging(True)
>
> or
>
> twistd --debug ...
>
> or
>
> trial --debug ...
>
> This causes Deferred to capture the stack at the time it is created and
> the time it is called back. The "Unhandled error" case will log this
> information. This should give you the traceback you want. This is not
> enabled by default because (I suppose) capturing stacks is very
> expensive.
I am not so interested in "debug runs", but more in a way to get more
informations of our tool stack bugs when run in production. I guess what
I am looking for is some good practices for dealing with errors, then.
Maybe a piece of code in twisted itself ?
cheers,
David
More information about the Twisted-Python
mailing list