From 51ebb7f4f5e9bdcf8279a1d91be9569706f6bead Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 17 Sep 2021 21:56:41 +0300 Subject: [PATCH] bpo-45187: Fix dangling threads in test_socket.CreateServerFunctionalTest (GH-28422) --- Lib/test/test_socket.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d064c6705a4..eeb8e8c98a1 100755 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -6528,13 +6528,6 @@ class CreateServerTest(unittest.TestCase): class CreateServerFunctionalTest(unittest.TestCase): timeout = support.LOOPBACK_TIMEOUT - def setUp(self): - self.thread = None - - def tearDown(self): - if self.thread is not None: - self.thread.join(self.timeout) - def echo_server(self, sock): def run(sock): with sock: @@ -6548,8 +6541,9 @@ class CreateServerFunctionalTest(unittest.TestCase): event = threading.Event() sock.settimeout(self.timeout) - self.thread = threading.Thread(target=run, args=(sock, )) - self.thread.start() + thread = threading.Thread(target=run, args=(sock, )) + thread.start() + self.addCleanup(thread.join, self.timeout) event.set() def echo_client(self, addr, family):