I ran your example, adding two lines to the bottom:
d.callback(None)
print("OK!")
and got this output:
Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
File "callbacks.py", line 11, in <module>
d.callback(None)
File ".../twisted/internet/defer.py", line 368, in callback
self._startRunCallbacks(result)
File ".../twisted/internet/defer.py", line 464, in _startRunCallbacks
self._runCallbacks()
--- <exception caught here> ---
File ".../twisted/internet/defer.py", line 551, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "callbacks.py", line 4, in bad_callback
raise Exception()
exceptions.Exception:
OK!
So in this specific case (as you have determined yourself), no, the exception won't be re-raised.
In the general case, there are a few places where exceptions will effectively propagate out; if you have a MemoryError
because you are totally out of memory, it's likely that the Deferred
implementation itself will allocate a little memory somewhere by attempting to call a function or something and that exception will come back to you.
But this is just a risk of programming in Python in general; there are several exceptions (MemoryError
, KeyboardInterrupt
) which may arise with no warning. If your whole process isn't burning down, then no, callback
and errback
won't raise exceptions except in the cases you've outlined.