]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45187: Fix dangling threads in test_socket.CreateServerFunctionalTest (GH-28422...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 17 Sep 2021 19:40:33 +0000 (12:40 -0700)
committerGitHub <noreply@github.com>
Fri, 17 Sep 2021 19:40:33 +0000 (22:40 +0300)
(cherry picked from commit 51ebb7f4f5e9bdcf8279a1d91be9569706f6bead)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_socket.py

index 54adf103e7e338ef223612d77cf38c8dc5b99729..5712b46f7f111a3512eb048dc7f4a2cc00fbc221 100755 (executable)
@@ -6482,13 +6482,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:
@@ -6502,8 +6495,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):