Close executor in event loop if interpreter is closing#6256
Merged
Close executor in event loop if interpreter is closing#6256
Conversation
Member
Author
|
Added test. I think that we used to have such a test. Maybe it was removed? I'd encourage folks to take a look in case it seems bad in some way. |
Contributor
fjetter
approved these changes
May 2, 2022
Comment on lines
+1604
to
+1607
| try: | ||
| await to_thread(_close) | ||
| except RuntimeError: # Are we shutting down the process? | ||
| _close() # Just run it directly |
Member
There was a problem hiding this comment.
I have a slight preference to be explicit here but I'm fine either way. The following works as well, at least for the test
Suggested change
| try: | |
| await to_thread(_close) | |
| except RuntimeError: # Are we shutting down the process? | |
| _close() # Just run it directly | |
| from distributed.utils import is_python_shutting_down | |
| if is_python_shutting_down(): | |
| # Scheduling new futures during shutdown is not allowed | |
| _close() | |
| else: | |
| await to_thread(_close) |
Member
Author
There was a problem hiding this comment.
My preference is to ask for forgiveness rather than permission here. I don't have enough confidence about Python shutting down to know all of the stages involved. Honestly I'd also be ok just except Exception here. The worst thing that can happen is that we call close again. I'd rather take the sledgehammer than the scalpel approach here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6255
Previously this would cause a RuntimeError during shutdown.
test incoming