]> granicus.if.org Git - python/commitdiff
bpo-31234: Join threads in tests (#3572)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 14 Sep 2017 15:43:04 +0000 (08:43 -0700)
committerGitHub <noreply@github.com>
Thu, 14 Sep 2017 15:43:04 +0000 (08:43 -0700)
Call thread.join() on threads to prevent the "dangling threads"
warning.

Lib/test/test_concurrent_futures.py
Lib/test/test_decimal.py
Lib/test/test_smtplib.py
Lib/test/test_xmlrpc.py

index 7bc733efb1eeb91dad075e6efd17269eee5d9c97..57dc994d28477065e29b20f470eb05046bbd8284 100644 (file)
@@ -772,6 +772,7 @@ class FutureTests(BaseTestCase):
         t.start()
 
         self.assertEqual(f1.result(timeout=5), 42)
+        t.join()
 
     def test_result_with_cancel(self):
         # TODO(brian@sweetapp.com): This test is timing dependent.
@@ -785,6 +786,7 @@ class FutureTests(BaseTestCase):
         t.start()
 
         self.assertRaises(futures.CancelledError, f1.result, timeout=5)
+        t.join()
 
     def test_exception_with_timeout(self):
         self.assertRaises(futures.TimeoutError,
@@ -813,6 +815,7 @@ class FutureTests(BaseTestCase):
         t.start()
 
         self.assertTrue(isinstance(f1.exception(timeout=5), OSError))
+        t.join()
 
 @test.support.reap_threads
 def test_main():
index 5d9da0e374584084bbf519ce6dc13bc969642b11..5aea51e8b732abc4f107269ad8272b04d7558210 100644 (file)
@@ -1618,6 +1618,9 @@ class ThreadingTest(unittest.TestCase):
         for sig in Signals[self.decimal]:
             self.assertFalse(DefaultContext.flags[sig])
 
+        th1.join()
+        th2.join()
+
         DefaultContext.prec = save_prec
         DefaultContext.Emax = save_emax
         DefaultContext.Emin = save_emin
index 4c9b7d367c8cd7e31f5602fbdfd4e24186d1a6c3..040ad4e05962ba5e31fc7ab2439e81dc7e02b8e6 100644 (file)
@@ -611,7 +611,9 @@ class TooLongLineTests(unittest.TestCase):
         self.sock.settimeout(15)
         self.port = support.bind_port(self.sock)
         servargs = (self.evt, self.respdata, self.sock)
-        threading.Thread(target=server, args=servargs).start()
+        thread = threading.Thread(target=server, args=servargs)
+        thread.start()
+        self.addCleanup(thread.join)
         self.evt.wait()
         self.evt.clear()
 
index f2b496ac9a64e6cca5c7c09e8bff63ff4c64ad76..c9099e0511770635d2b17d8e6e282006cd94f0a9 100644 (file)
@@ -755,7 +755,9 @@ class BaseServerTestCase(unittest.TestCase):
         self.evt = threading.Event()
         # start server thread to handle requests
         serv_args = (self.evt, self.request_count, self.requestHandler)
-        threading.Thread(target=self.threadFunc, args=serv_args).start()
+        thread = threading.Thread(target=self.threadFunc, args=serv_args)
+        thread.start()
+        self.addCleanup(thread.join)
 
         # wait for the server to be ready
         self.evt.wait()
@@ -1206,7 +1208,9 @@ class FailingServerTestCase(unittest.TestCase):
         self.evt = threading.Event()
         # start server thread to handle requests
         serv_args = (self.evt, 1)
-        threading.Thread(target=http_server, args=serv_args).start()
+        thread = threading.Thread(target=http_server, args=serv_args)
+        thread.start()
+        self.addCleanup(thread.join)
 
         # wait for the server to be ready
         self.evt.wait()