[Python-checkins] [3.10] gh-91676 gh-91260 unittest.IsolatedAsyncioTestCase no longer leaks its executor (GH-91680)

pablogsal webhook-mailer at python.org
Tue Apr 19 05:31:55 EDT 2022


https://github.com/python/cpython/commit/61570ae0bc1507a62bee9d8b9bc2ff7155da7061
commit: 61570ae0bc1507a62bee9d8b9bc2ff7155da7061
branch: 3.10
author: Gregory P. Smith <greg at krypto.org>
committer: pablogsal <Pablogsal at gmail.com>
date: 2022-04-19T10:31:50+01:00
summary:

[3.10] gh-91676 gh-91260 unittest.IsolatedAsyncioTestCase no longer leaks 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.

files:
A Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst
M Lib/unittest/async_case.py

diff --git a/Lib/unittest/async_case.py b/Lib/unittest/async_case.py
index 23231199f9870..d9c694e368255 100644
--- a/Lib/unittest/async_case.py
+++ b/Lib/unittest/async_case.py
@@ -148,6 +148,8 @@ def _tearDownAsyncioLoop(self):
             # shutdown asyncgens
             loop.run_until_complete(loop.shutdown_asyncgens())
         finally:
+            # Prevent our executor environment from leaking to future tests.
+            loop.run_until_complete(loop.shutdown_default_executor())
             asyncio.set_event_loop(None)
             loop.close()
 
diff --git a/Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst b/Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst
new file mode 100644
index 0000000000000..dfbaef4440e0a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-04-19-04-33-39.gh-issue-91676.ceQBwh.rst
@@ -0,0 +1,4 @@
+Fix :class:`unittest.IsolatedAsyncioTestCase` to shutdown the per test event
+loop executor before returning from its ``run`` method so that a not yet
+stopped or garbage collected executor state does not persist beyond the
+test.



More information about the Python-checkins mailing list