]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39010: Improve test shutdown (GH-22066) (#22083)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 3 Sep 2020 20:54:36 +0000 (13:54 -0700)
committerGitHub <noreply@github.com>
Thu, 3 Sep 2020 20:54:36 +0000 (13:54 -0700)
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
(cherry picked from commit be435ae2b064dc64f04475bec632862e1dbf605f)

Co-authored-by: Ben Darnell <ben@bendarnell.com>
Co-authored-by: Ben Darnell <ben@bendarnell.com>
Lib/test/test_asyncio/test_windows_events.py

index 33388a87d48f3f178ab1041552e762b17b173f6e..f276cd205a2f8e9de5fb2b69522f200b31214044 100644 (file)
@@ -225,10 +225,18 @@ class ProactorTests(test_utils.TestCase):
         self.loop.run_forever()
         self.loop.stop()
         self.loop.run_forever()
-        # 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.run_until_complete(f)
-        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)
         self.assertFalse(self.loop.call_exception_handler.called)