diff options
author | Thomas Moreau <thomas.moreau.2010@gmail.com> | 2019-04-24 19:45:52 (GMT) |
---|---|---|
committer | Antoine Pitrou <antoine@python.org> | 2019-04-24 19:45:52 (GMT) |
commit | 004b93ea8947bcbe85b6fa16fe0999bfa712d5c1 (patch) | |
tree | f878d3c76b355822e4f88bc92f55a6511bd9dd4f /Lib/test/_test_multiprocessing.py | |
parent | 09d434caa2c01477ea2ccc3e9b88e9faa0107c61 (diff) | |
download | cpython-004b93ea8947bcbe85b6fa16fe0999bfa712d5c1.zip cpython-004b93ea8947bcbe85b6fa16fe0999bfa712d5c1.tar.gz cpython-004b93ea8947bcbe85b6fa16fe0999bfa712d5c1.tar.bz2 |
bpo-36668: FIX reuse semaphore tracker for child processes (#5172)
Fix the multiprocessing.semaphore_tracker so it is reused by child processes.
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 553ab81..836fde8 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -4891,6 +4891,34 @@ class TestSemaphoreTracker(unittest.TestCase): # Uncatchable signal. self.check_semaphore_tracker_death(signal.SIGKILL, True) + @staticmethod + def _is_semaphore_tracker_reused(conn, pid): + from multiprocessing.semaphore_tracker import _semaphore_tracker + _semaphore_tracker.ensure_running() + # The pid should be None in the child process, expect for the fork + # context. It should not be a new value. + reused = _semaphore_tracker._pid in (None, pid) + reused &= _semaphore_tracker._check_alive() + conn.send(reused) + + def test_semaphore_tracker_reused(self): + from multiprocessing.semaphore_tracker import _semaphore_tracker + _semaphore_tracker.ensure_running() + pid = _semaphore_tracker._pid + + r, w = multiprocessing.Pipe(duplex=False) + p = multiprocessing.Process(target=self._is_semaphore_tracker_reused, + args=(w, pid)) + p.start() + is_semaphore_tracker_reused = r.recv() + + # Clean up + p.join() + w.close() + r.close() + + self.assertTrue(is_semaphore_tracker_reused) + class TestSimpleQueue(unittest.TestCase): |