-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-39349: Add *cancel_futures* to Executor.shutdown() #18057
bpo-39349: Add *cancel_futures* to Executor.shutdown() #18057
Conversation
The current version of the documentation and tests does cover what happens when That being said, I think it might be worth elaborating on the behavior when ThreadPoolExecutor - All work items still in the queue (meaning they haven't been assigned to a thread yet) are removed from the queue, and their associated futures are cancelled. This occurs regardless of the value of When The difference between using ProcessPoolExecutor - Most of the above applies, but underlying details differ a bit. In PPE, the pending work items are not directly accessible in This results in a bit of delay from when the flag is set to when the pending futures are cancelled, but I think this is the best way to implement cancel_futures for PPE without causing substantial performance losses. IMO, it's preferable to delay cancelling a few pending futures (allowing them to run) and have better overall performance. Admittedly though, I don't have a strong understanding of the specifics that occur though when I suspect it has to do with the way non-joined processes are finalized during interpreter shutdown, but that's not an area I'm particularly knowledgeable with. Maybe @pitrou could clarify? I just found this out while writing an example to demonstrate the above. In my own personal usage of Examples: Interaction between wait and cancel_futures: https://gist.github.com/aeros/2e73c8d6dccc94fd863967715826c78d PPE deadlock demo: https://gist.github.com/aeros/d1ff62b730426584413bca0c8f2ed99d Edit: I made the current documentation more explicit about what happens when |
Thanks for the review @brianquinlan! I'll go ahead and make some of the recommend changes while waiting on your response to the above comment. |
…tps://github.com/aeros/cpython into bpo39349-add-cancel_futures-to-Executor.shutdown
Hey Kyle, I know I've promised you a review for this, but I've been distracted by various other things. Now that you've got Brian reviewing your code that's actually much better. Once Brian approves I can rubber-stamp and merge it. (Let me know if you have specific questions for me.) |
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-authored-by: Brian Quinlain <[email protected]>
I have made the requested changes; please review again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions and comments below. Sorry for the last-minute review.
Sounds good! I believe @gvanrossum was previously going to merge the PR since he had brought some attention to the feature, and I had agreed to implement it. But I'm perfectly happy with you or @pitrou merging it whenever you think it's ready, especially as the resident experts for
No problem, thanks for review. I'd rather make the implementation of |
To ensure this works across platforms prior to merging the PR, I think it might be a good idea to make use of the new Note: I noticed that |
The two buildbot failures as well as the Azure Pipelines failure look unrelated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 from me. Thank you @aeros for doing this !
Can you push a dummy commit to restart the CI? |
Yep, Steve Dower advised me to close and re-open the PR to reset the CI in python-dev when I asked about the Azure Pipelines failure, and informed me that the two failing buildbots are not working for 3.9, but haven't been disabled yet. I'll go ahead and close/re-open it. |
No problem, thanks again for the reviews @brianquinlan and @pitrou! This issue turned out to be a bit more involved than I had initially anticipated, but I learned quite a lot about the internal implementation details of the executors, especially ProcessPoolExecutor. |
There seemed to be an unrelated issue in the checkout stage for the most recent GitHub Actions CI for |
…ythonGH-22023) * Add cancel_futures parameter to the Executor base class, since it was missed in the original PR (python#18057) that added cancel_futures. (cherry picked from commit 17dc1b7) Co-authored-by: Shantanu <[email protected]>
…GH-22023) * Add cancel_futures parameter to the Executor base class, since it was missed in the original PR (python#18057) that added cancel_futures.
* Add cancel_futures parameter to the Executor base class, since it was missed in the original PR (python/cpython#18057) that added cancel_futures.
https://bugs.python.org/issue39349