[Twisted-Python] how to write a safe catch-all
p.mayers at imperial.ac.uk
Thu Sep 30 09:03:01 EDT 2010
On 30/09/10 13:44, Phil Mayers wrote:
> This is because (as you've discovered) there are circumstances when a
> function is called in Twisted where the exception can't propagate "up"
> to the caller, because the caller is no longer higher in the call stack.
> Most prominent is reactor.callLater.
One quick thing you might be able to do is use t.i.task.deferLater
instead of reactor.callLater, like so:
breakobj = Break()
d = task.deferLater(reactor, 2, breakobj)
task.deferLater will schedule the call, but runs the call in a context
which means any exceptions raised flow down the deferred errback. This:
except Exception, e:
...will then work, and "see" the exception.
More information about the Twisted-Python