Skip to content

EXECUTOR_PROPAGATE_EXCEPTIONS does not propagate exceptions #24

@okke-formsma

Description

@okke-formsma

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:

future.result()

I think it is impossible to have other threads interrupt the main thread when they encounter an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions