[Twisted-Python] Understanding deferred and error handling
Jason Rennie
jrennie at gmail.com
Wed Apr 20 04:15:08 MDT 2011
On Wed, Apr 20, 2011 at 12:28 AM, David <david at silveregg.co.jp> wrote:
> def _stop(arg):
> reactor.stop()
> d.addBoth(_stop)
>
Try using addCallbacks instead of addBoth. Then, you can logically separate
code to handle/print errors from "normal" code.
This will simply print no error in the log:
>
That's because you discarded the twisted.python.failure.Failure object by
using _stop for your errback and not doing anything with the arg. Similar
to try/except with a "pass" in the "except" clause.
def log_error(failure):
log.err(failure.printTraceback())
> return failure
> d.addErrback(log_error)
> d.addBoth(_stop)
>
Use d.addCallbacks(_stop, log_error) instead of addBoth/addErrback. Also,
you probably want "log.err(failure.getTraceback())" instead of
"log.err(failure.printTraceback())". printTraceback does not return a
meaningful value IIUC.
I don't get any traceback either.
>
Your traceback went to stdout whereas you were probably watching stderr or a
log file.
Jason
--
Jason Rennie
Research Scientist, ITA Software
617-714-2645
http://www.itasoftware.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20110420/6708b033/attachment.html>
More information about the Twisted-Python
mailing list