Futures will swallow all exceptions thrown by callbacks added to the future using the _done_callbacks:
# concurrent.futures._base
class Future(object):
"""Represents the result of an asynchronous computation."""
# ...
def _invoke_callbacks(self):
for callback in self._done_callbacks:
try:
callback(self)
except Exception:
LOGGER.exception('exception calling callback for %r', self)
The tests pass because the propagate_exceptions_callback is called explicitly. However, this bypasses the configuration setting completely.
def test_propagate_exception_callback(app, caplog):
caplog.set_level(logging.ERROR)
app.config['EXECUTOR_PROPAGATE_EXCEPTIONS'] = True # the test succeeds even if this is false
executor = Executor(app)
with pytest.raises(NameError):
with app.test_request_context('/'):
future = executor.submit(fail)
assert propagate_exceptions_callback in future._done_callbacks
concurrent.futures.wait([future])
propagate_exceptions_callback(future) # without this line the test fails
To ensure an exception will be raised when the thread had an exception, just access the future's result:
I think it is impossible to have other threads interrupt the main thread when they encounter an exception.
Futures will swallow all exceptions thrown by callbacks added to the future using the _done_callbacks:
The tests pass because the
propagate_exceptions_callbackis called explicitly. However, this bypasses the configuration setting completely.To ensure an exception will be raised when the thread had an exception, just access the future's result:
I think it is impossible to have other threads interrupt the main thread when they encounter an exception.