[Twisted-Python] Catching all the exceptions in a Twisted program
Facundo Batista
facundobatista at gmail.com
Mon Oct 25 06:57:38 EDT 2010
Hello!
I've just subscribed to the list, but I'm using Twisted from a while ago.
I need to do something, and wasn't able to find out how to do it. Well, I
*did* find out, but it's a horrible hack, and actually depends on something
that may be a bug, so it's worth asking here about this :)
In a project I'm doing [0], I want to catch all problems (unhandled
exceptions), log them and show them in stderr after a bit massaging. My
first approach was to hook me in sys.excepthook, and it worked on some
cases. But I saw some cases where it didn't [1].
Specifically, when the exception was inside a deferred, it didn't call
excepthook. Why not? I started to check the code, and found the following
snippet, at the end of Deferred._run_callbacks, in defer.py:
if isinstance(self.result, failure.Failure):
self.result.cleanFailure()
if self._debugInfo is None:
self._debugInfo = DebugInfo()
self._debugInfo.failResult = self.result
More information about the Twisted-Python
mailing list