diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-07 01:05:02 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-07 01:05:02 +0100 |
commit | 8c10bc4e75d9748e63ce86ce785955bf378546b3 (patch) | |
tree | 45e26df0fcf5f15ea18451fa4ed1a0d5b5e0a323 | |
parent | 6b8836a4dcbc9945d4d05f38472d6bed00132d6e (diff) | |
download | cpython-git-8c10bc4e75d9748e63ce86ce785955bf378546b3.tar.gz |
attempt adding synchronization primitive to wait for the subprocess to exit
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 7c36038e35..b57f5a125c 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -4742,14 +4742,35 @@ class TestSyncManagerTypes(unittest.TestCase): self.manager.shutdown() @classmethod - def tearDownClass(cls): + def setUpClass(cls): support.reap_children() + tearDownClass = setUpClass + + def wait_proc_exit(self): + # Only the manager process should be returned by active_children() + # but this can take a bit on slow machines, so wait a few seconds + # if there are other children too (see #17395). + join_process(self.proc) + start_time = time.monotonic() + t = 0.01 + while len(multiprocessing.active_children()) > 1: + time.sleep(t) + t *= 2 + dt = time.monotonic() - start_time + if dt >= 5.0: + test.support.environment_altered = True + print("Warning -- multiprocessing.Manager still has %s active " + "children after %s seconds" + % (multiprocessing.active_children(), dt), + file=sys.stderr) + break + def run_worker(self, worker, obj): self.proc = multiprocessing.Process(target=worker, args=(obj, )) self.proc.daemon = True self.proc.start() - join_process(self.proc) + self.wait_proc_exit() self.assertEqual(self.proc.exitcode, 0) @classmethod |