[Python-checkins] bpo-45187: Fix dangling threads in test_socket.CreateServerFunctionalTest (GH-28422) (GH-28424)

serhiy-storchaka webhook-mailer at python.org
Fri Sep 17 15:40:50 EDT 2021


https://github.com/python/cpython/commit/6c50f23ae085ec66f320a26a3f0a6c60d7f2b29d
commit: 6c50f23ae085ec66f320a26a3f0a6c60d7f2b29d
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2021-09-17T22:40:33+03:00
summary:

bpo-45187: Fix dangling threads in test_socket.CreateServerFunctionalTest (GH-28422) (GH-28424)

(cherry picked from commit 51ebb7f4f5e9bdcf8279a1d91be9569706f6bead)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
M Lib/test/test_socket.py

diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 54adf103e7e33..5712b46f7f111 100755
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -6482,13 +6482,6 @@ def test_dualstack_ipv6_family(self):
 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 @@ def run(sock):
 
         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):



More information about the Python-checkins mailing list