Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions Lib/test/fork_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)

Expand All @@ -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