-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-111358: Fix timeout behaviour in BaseEventLoop.shutdown_default_executor #115622
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
gh-111358: Fix timeout behaviour in BaseEventLoop.shutdown_default_executor #115622
Conversation
@ordinary-jamie Can you look into the test failures? They all look related to |
This can cleanly be backported to 3.12, but not to 3.11 -- that doesn't have the Either way, while this PR fixes the timeout logic, it doesn't really help the OP of gh-111358 -- it'll still wait 300 seconds for the shutdown upon receiving the first But I'll note that this isn't entirely asyncio's fault -- if you use an executor to sleep 1000 seconds and print the result, it'll take two Also, I might as well ping @kumaraditya303, to see if he agrees with our analysis. We made the mistake in gh-97561 (which he cleaned up and committed but didn't write) not to add a test. :-( |
Sorry! Didn't notice these yesterday. Took a look at it appears our issue it because the Lines 15 to 19 in ded5f1f
Pushed a fix to temporarily fix the warning filter for this case |
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("default") |
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.
I see. It seems that in tests, using catch_warnings()
requires simplefilter()
, otherwise the test fails when using -Werror
. Is there any particular reason you're not using assertWarns()
though? It takes care of this.
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.
No reason (besides me not knowing about that method, sorry). Updated!
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.
Now you know. :-)
Looks good, I'll merge.
Thanks @ordinary-jamie for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…ult_executor (pythonGH-115622) (cherry picked from commit 53d5e67) Co-authored-by: Jamie Phan <[email protected]>
GH-115641 is a backport of this pull request to the 3.12 branch. |
…ault_executor (GH-115622) (#115641) (cherry picked from commit 53d5e67) Co-authored-by: Jamie Phan <[email protected]>
Fixes the timeout behaviour in
asyncio.BaseEventLoop.shutdown_default_executor
to ensure that the coroutine correctly times-out when awaiting the shutdown thread.If the timeout is reaching, the thread is left to run, and is not joined (since waiting for the thread to join in this case would exceed the timeout). The Executor is shutdown without waiting.
Minor updates to
_do_shutdown
to ensure future isn't cancelled. This is necessary since the thread can still run and attempt to set the future result/exception