Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-05-23.07:40:04.581>created_at=<Date2018-03-20.16:12:43.307>labels= ['3.7', '3.8', 'type-bug', 'library']
title='Adding a done callback to a concurrent.futures Future once it has already completed, may raise an exception, contrary to docs'updated_at=<Date2019-05-23.07:40:04.581>user='https://github.com/ABitMoreDepth'
Whilst working with concurrent.futures and ThreadPoolExecutors, my colleague and I have noted some undocumented behaviour.
When adding a done_callback to a future that has already completed, we note that that callback is executed directly, outside of any try...except statement. However, both the docs and the _invoke_callbacks methods will wrap any done_callbacks in a try...except statement which logs the result and returns.
Could we either update the documentation to mention that callback behaviour may raise if added to an already completed future, or simply add the same try...except wrapping that the _invoke_callback method already uses please? (Preferably the latter)
I would note, that the test code which covers this area of the code, doesn't currently exercise this particular condition. The closest test I could find is test_done_callback_already_failed, which checks that a callback can retrieve an exception from a future, but it does not validate what happens when a callback raises when the future it is attached to is already complete.
Source:
The other test closely related is test_done_callback_raises, however this doesn't check the behaviour of a callback when added to an already completed future. We should be able to simulate this by moving the f.set_result line to above the f.add_done_callback lines?
New changeset 2a3a2ec by Antoine Pitrou (Sam Martin) in branch 'master': bpo-33110: Catch errors raised when running add_done_callback on already completed futures (GH-13141) 2a3a2ec
New changeset b73c21c by Miss Islington (bot) in branch '3.7': bpo-33110: Catch errors raised when running add_done_callback on already completed futures (GH-13141) b73c21c
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: