Skip to content

bpo-33110: Catches errors raised when running add_done_callback on already completed futures.#13141

Merged
pitrou merged 3 commits intopython:masterfrom
martsa1:futures-fix
May 22, 2019
Merged

bpo-33110: Catches errors raised when running add_done_callback on already completed futures.#13141
pitrou merged 3 commits intopython:masterfrom
martsa1:futures-fix

Conversation

@martsa1
Copy link
Copy Markdown

@martsa1 martsa1 commented May 6, 2019

Wraps the callback call within the add_done_callback function within concurrent.futures, in order to behave in an identical manner to callbacks added to a running future are triggered once it has completed.

Prior to this change, adding a callback to a future which has already completed, which raises, will allow that exception to raise, where running that callback later (i.e. once a future completes), wraps the callback execution in a try..except statement. This pull request matches that behavior for callbacks added to an already complete future.

I feel this brings the add_done_callback behavior inline with the documentation. I have added a unit test alongside this change which demonstrates the behavior.

Please let me know if there's anything I need to tweak here etc.

https://bugs.python.org/issue33110

…ready completed futures.

Wraps the callback call within the `add_done_callback` function within
concurrent.futures, in order to behave in an identical manner to
callbacks added to a running future are triggered once it has completed.
@the-knights-who-say-ni
Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Our records indicate we have not received your CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@martsa1
Copy link
Copy Markdown
Author

martsa1 commented May 6, 2019

CLA has been signed, hopefully will propagate through shortly.

@brianquinlan
Copy link
Copy Markdown
Contributor

The previous behavior was a bug. This fix also seems reasonably safe because the pre-PR behavior is timing dependent anyway.

@brianquinlan
Copy link
Copy Markdown
Contributor

LGTM. You'll need a committer review.

@csabella csabella requested a review from pitrou May 13, 2019 22:20
Copy link
Copy Markdown
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @ABitMoreDepth for the PR, and @pitrou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington
Copy link
Copy Markdown
Contributor

Thanks @ABitMoreDepth for the PR, and @pitrou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 22, 2019
…ady completed futures (pythonGH-13141)

Wrap the callback call within the `add_done_callback` function within concurrent.futures, in order to behave in an identical manner to callbacks added to a running future are triggered once it has completed.
(cherry picked from commit 2a3a2ec)

Co-authored-by: Sam Martin <ABitMoreDepth@users.noreply.github.com>
@bedevere-bot
Copy link
Copy Markdown

GH-13508 is a backport of this pull request to the 3.7 branch.

@bedevere-bot
Copy link
Copy Markdown

GH-13509 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 22, 2019
…ady completed futures (pythonGH-13141)

Wrap the callback call within the `add_done_callback` function within concurrent.futures, in order to behave in an identical manner to callbacks added to a running future are triggered once it has completed.
(cherry picked from commit 2a3a2ec)

Co-authored-by: Sam Martin <ABitMoreDepth@users.noreply.github.com>
@martsa1 martsa1 deleted the futures-fix branch May 22, 2019 21:32
miss-islington added a commit that referenced this pull request May 22, 2019
…ady completed futures (GH-13141)

Wrap the callback call within the `add_done_callback` function within concurrent.futures, in order to behave in an identical manner to callbacks added to a running future are triggered once it has completed.
(cherry picked from commit 2a3a2ec)

Co-authored-by: Sam Martin <ABitMoreDepth@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants