[Python-checkins] bpo-31234: fork_wait tests now join threads (#3139) (#3535)

Victor Stinner webhook-mailer at python.org
Wed Sep 13 06:26:56 EDT 2017


https://github.com/python/cpython/commit/42f7e0d8b0ca940a809a786f25d967dcce4d71b6
commit: 42f7e0d8b0ca940a809a786f25d967dcce4d71b6
branch: 2.7
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-09-13T03:26:54-07:00
summary:

bpo-31234: fork_wait tests now join threads (#3139) (#3535)

fork_wait.py tests now joins threads, to not leak running threads in
the background.

(cherry picked from commit c99d41f9c0304fcf06550515c3db55f93a629e9e)

files:
M Lib/test/fork_wait.py

diff --git a/Lib/test/fork_wait.py b/Lib/test/fork_wait.py
index 2646cbd5816..b900463da60 100644
--- a/Lib/test/fork_wait.py
+++ b/Lib/test/fork_wait.py
@@ -13,8 +13,9 @@
 """
 
 import os, sys, time, unittest
-import test.test_support as test_support
-thread = test_support.import_module('thread')
+import test.support as support
+
+threading = support.import_module('threading')
 
 LONGSLEEP = 2
 SHORTSLEEP = 0.5
@@ -23,8 +24,19 @@
 class ForkWait(unittest.TestCase):
 
     def setUp(self):
+        self._threading_key = support.threading_setup()
         self.alive = {}
         self.stop = 0
+        self.threads = []
+
+    def tearDown(self):
+        # Stop threads
+        self.stop = 1
+        for thread in self.threads:
+            thread.join()
+        thread = None
+        del self.threads[:]
+        support.threading_cleanup(*self._threading_key)
 
     def f(self, id):
         while not self.stop:
@@ -48,7 +60,9 @@ def wait_impl(self, cpid):
 
     def test_wait(self):
         for i in range(NUM_THREADS):
-            thread.start_new(self.f, (i,))
+            thread = threading.Thread(target=self.f, args=(i,))
+            thread.start()
+            self.threads.append(thread)
 
         time.sleep(LONGSLEEP)
 
@@ -74,6 +88,3 @@ def test_wait(self):
         else:
             # Parent
             self.wait_impl(cpid)
-            # Tell threads to die
-            self.stop = 1
-            time.sleep(2*SHORTSLEEP) # Wait for threads to die



More information about the Python-checkins mailing list