Skip to content

Commit 42f7e0d

Browse files
authored
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 c99d41f)
1 parent 40996d3 commit 42f7e0d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Lib/test/fork_wait.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
"""
1414

1515
import os, sys, time, unittest
16-
import test.test_support as test_support
17-
thread = test_support.import_module('thread')
16+
import test.support as support
17+
18+
threading = support.import_module('threading')
1819

1920
LONGSLEEP = 2
2021
SHORTSLEEP = 0.5
@@ -23,8 +24,19 @@
2324
class ForkWait(unittest.TestCase):
2425

2526
def setUp(self):
27+
self._threading_key = support.threading_setup()
2628
self.alive = {}
2729
self.stop = 0
30+
self.threads = []
31+
32+
def tearDown(self):
33+
# Stop threads
34+
self.stop = 1
35+
for thread in self.threads:
36+
thread.join()
37+
thread = None
38+
del self.threads[:]
39+
support.threading_cleanup(*self._threading_key)
2840

2941
def f(self, id):
3042
while not self.stop:
@@ -48,7 +60,9 @@ def wait_impl(self, cpid):
4860

4961
def test_wait(self):
5062
for i in range(NUM_THREADS):
51-
thread.start_new(self.f, (i,))
63+
thread = threading.Thread(target=self.f, args=(i,))
64+
thread.start()
65+
self.threads.append(thread)
5266

5367
time.sleep(LONGSLEEP)
5468

@@ -74,6 +88,3 @@ def test_wait(self):
7488
else:
7589
# Parent
7690
self.wait_impl(cpid)
77-
# Tell threads to die
78-
self.stop = 1
79-
time.sleep(2*SHORTSLEEP) # Wait for threads to die

0 commit comments

Comments
 (0)