Skip to content

GH-96827: Don't touch closed loops from executor threads - #96837

Merged
gvanrossum merged 4 commits into
python:mainfrom
gvanrossum:asyncio-thread-late
Sep 30, 2022
Merged

gvanrossum merged 4 commits into
python:mainfrom
gvanrossum:asyncio-thread-late

Conversation

@gvanrossum

Copy link
Copy Markdown
Member

It's possible for an event loop's default executor to survive the loop. When the executor is finally shut down, a few things try to wake up the loop, and nasty RuntimeErrors are printed. But there's nothing the executor can do about that, so let's just not even try.

This is a draft PR because I haven't figured out a way to test this properly. (There's a repro in the issue, GH-96827.)

@kumaraditya303
kumaraditya303 self-requested a review September 17, 2022 10:29
@gvanrossum
gvanrossum marked this pull request as ready for review September 29, 2022 22:06
@gvanrossum

Copy link
Copy Markdown
Member Author

At this point (after investing over an hour of my time) I feel it's not worth it to try and come up with a test that reproduces the original issue. The changes appear straightforward enough: in certain edge cases don't attempt to set a future's state when its loop is already closed.

@kumaraditya303 kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@gvanrossum
gvanrossum merged commit e9d6376 into python:main Sep 30, 2022
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @gvanrossum for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@gvanrossum
gvanrossum deleted the asyncio-thread-late branch September 30, 2022 19:55
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Sep 30, 2022
@bedevere-bot

Copy link
Copy Markdown

GH-97690 is a backport of this pull request to the 3.11 branch.

@bedevere-bot

Copy link
Copy Markdown

GH-97691 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 30, 2022
…nGH-96837)

* When chaining futures, skip callback if loop closed.
* When shutting down an executor, don't wake a closed loop.
(cherry picked from commit e9d6376)

Co-authored-by: Guido van Rossum <guido@python.org>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 30, 2022
…nGH-96837)

* When chaining futures, skip callback if loop closed.
* When shutting down an executor, don't wake a closed loop.
(cherry picked from commit e9d6376)

Co-authored-by: Guido van Rossum <guido@python.org>
miss-islington added a commit that referenced this pull request Sep 30, 2022
* When chaining futures, skip callback if loop closed.
* When shutting down an executor, don't wake a closed loop.
(cherry picked from commit e9d6376)

Co-authored-by: Guido van Rossum <guido@python.org>
miss-islington added a commit that referenced this pull request Sep 30, 2022
* When chaining futures, skip callback if loop closed.
* When shutting down an executor, don't wake a closed loop.
(cherry picked from commit e9d6376)

Co-authored-by: Guido van Rossum <guido@python.org>
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Oct 2, 2022
…n#96837)

* When chaining futures, skip callback if loop closed.
* When shutting down an executor, don't wake a closed loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants