[Python-checkins] bpo-39010: Improve test shutdown (#22066)

Ben Darnell webhook-mailer at python.org
Thu Sep 3 00:58:54 EDT 2020

commit: be435ae2b064dc64f04475bec632862e1dbf605f
branch: master
author: Ben Darnell <ben at bendarnell.com>
committer: GitHub <noreply at github.com>
date: 2020-09-02T21:58:50-07:00

bpo-39010: Improve test shutdown (#22066)

Simply closing the event loop isn't enough to avoid warnings. If we
don't also shut down the event loop's default executor, it sometimes
logs a "dangling thread" warning.

Follow-up to GH-22017

M Lib/test/test_asyncio/test_windows_events.py

diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py
index 33388a87d48f3..f276cd205a2f8 100644
--- a/Lib/test/test_asyncio/test_windows_events.py
+++ b/Lib/test/test_asyncio/test_windows_events.py
@@ -225,10 +225,18 @@ def test_read_self_pipe_restart(self):
-        # If we don't wait for f to complete here, we may get another
-        # warning logged about a thread that didn't shut down cleanly.
+        # Shut everything down cleanly. This is an important part of the
+        # test - in issue 39010, the error occurred during loop.close(),
+        # so we want to close the loop during the test instead of leaving
+        # it for tearDown.
+        #
+        # First wait for f to complete to avoid a "future's result was never
+        # retrieved" error.
-        self.loop.close()
+        # Now shut down the loop itself (self.close_loop also shuts down the
+        # loop's default executor).
+        self.close_loop(self.loop)

More information about the Python-checkins mailing list