Skip to content

Commit 40e2444

Browse files
bpo-39010: Improve test shutdown (pythonGH-22066) (python#22083)
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 pythonGH-22017 (cherry picked from commit be435ae) Co-authored-by: Ben Darnell <ben@bendarnell.com> Co-authored-by: Ben Darnell <ben@bendarnell.com>
1 parent 1f5f127 commit 40e2444

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Lib/test/test_asyncio/test_windows_events.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,18 @@ def test_read_self_pipe_restart(self):
225225
self.loop.run_forever()
226226
self.loop.stop()
227227
self.loop.run_forever()
228-
# If we don't wait for f to complete here, we may get another
229-
# warning logged about a thread that didn't shut down cleanly.
228+
229+
# Shut everything down cleanly. This is an important part of the
230+
# test - in issue 39010, the error occurred during loop.close(),
231+
# so we want to close the loop during the test instead of leaving
232+
# it for tearDown.
233+
#
234+
# First wait for f to complete to avoid a "future's result was never
235+
# retrieved" error.
230236
self.loop.run_until_complete(f)
231-
self.loop.close()
237+
# Now shut down the loop itself (self.close_loop also shuts down the
238+
# loop's default executor).
239+
self.close_loop(self.loop)
232240
self.assertFalse(self.loop.call_exception_handler.called)
233241

234242

0 commit comments

Comments
 (0)