[Twisted-Python] A few simple questions
itamar at itamarst.org
Wed Jul 18 14:18:59 EDT 2012
On 07/18/2012 01:31 PM, Russell E. Owen wrote:
> If there is a "best practices for error handling" document I'd love to
> read it. I found an overview of deferreds that was helpful. It pointed
> out that addCallbacks is not the same as addCallback followed by
> addErrback and I'm not sure I'm handling the difference correctly. Right
> now I use addCallbacks(callback, errback). This does not call the
> errback if the callback fails. I do this intentionally because I want
> the errback to focus on problems with the connection, not my reaction to
> it, and the default error handler seems to report errors in the
> callback, which is fine.
One thing to realize is that errors that end up in a Deferred are only
logged if it gets garbage collected... which won't happen if you keep a
reference to it. So:
1. You should always delete a reference to a Deferred when you do
callback() or errback().
2. In case it never gets GC'ed, always do .addErrback(log.err) as the
last callback on the Deferred, if there's no other final error handler.
More information about the Twisted-Python