Skip to content

[3.10] gh-91676 gh-91260 unittest.IsolatedAsyncioTestCase no longer leaks its executor #91680

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

Merged
merged 2 commits into from
Apr 19, 2022

Conversation

gpshead
Copy link
Member

@gpshead gpshead commented Apr 19, 2022

For things like test_asyncio.test_thread this was causing frequent
"environment modified by test" errors as the executor threads had not
always stopped running after the test was over.

issues #91676 and #91260 alternate fix to #91667.

This only happened in 3.10 and 3.9 after #32086 as the main 3.11 branch has a completely rewritten unittest.IsolatedAsyncioTestCase that uses asyncio APIs itself that do not appear to leak the executor.

For things like test_asyncio.test_thread this was causing frequent
"environment modified by test" errors as the executor threads had not
always stopped running after the test was over.
@gpshead gpshead added type-bug An unexpected behavior, bug, or error needs backport to 3.9 only security fixes stdlib Python modules in the Lib dir 3.10 only security fixes 3.9 only security fixes labels Apr 19, 2022
@gpshead gpshead requested a review from asvetlov April 19, 2022 04:25
@gpshead
Copy link
Member Author

gpshead commented Apr 19, 2022

@asvetlov is this unittest.IsolatedAsyncioTestCase change to make in stable releases or should #91667 proceed to simply revert your test_asyncio.test_threads.py PR in the 3.10 and 3.9 branches?

I believe it to be what people want this class to do. But https://docs.python.org/3.11/library/unittest.html#unittest.IsolatedAsyncioTestCase.run says nothing more than "sets up a new event loop to run the test ... at the end tasks in the event loop are cancelled" without explicitly stating what should be obvious that upon exit this new private event loop should go away.

So I believe this unittest bugfix is desirable. There appears no nice way to inject this shutdown_default_executor() call as a workaround for anyone already using this class given the way the code in 3.10 and earlier is structured.

@gpshead gpshead changed the title gh-91676 gh-91260 unittest.IsolatedAsyncioTestCase no longer leaks its executor [3.10] gh-91676 gh-91260 unittest.IsolatedAsyncioTestCase no longer leaks its executor Apr 19, 2022
@gpshead gpshead requested a review from pablogsal April 19, 2022 04:35
@gpshead gpshead self-assigned this Apr 19, 2022
@pablogsal pablogsal merged commit 61570ae into python:3.10 Apr 19, 2022
@miss-islington
Copy link
Contributor

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 19, 2022
… no longer leaks its executor (pythonGH-91680)

For things like test_asyncio.test_thread this was causing frequent
"environment modified by test" errors as the executor threads had not
always stopped running after the test was over.
(cherry picked from commit 61570ae)

Co-authored-by: Gregory P. Smith <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Apr 19, 2022
@bedevere-bot
Copy link

GH-91692 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit that referenced this pull request Apr 19, 2022
…eaks its executor (GH-91680)

For things like test_asyncio.test_thread this was causing frequent
"environment modified by test" errors as the executor threads had not
always stopped running after the test was over.
(cherry picked from commit 61570ae)

Co-authored-by: Gregory P. Smith <[email protected]>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
… no longer leaks its executor (pythonGH-91680)

For things like test_asyncio.test_thread this was causing frequent
"environment modified by test" errors as the executor threads had not
always stopped running after the test was over.
(cherry picked from commit 61570ae)

Co-authored-by: Gregory P. Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
4 participants