diff options
author | Richard Oudkerk <shibturn@gmail.com> | 2013-04-17 19:58:00 (GMT) |
---|---|---|
committer | Richard Oudkerk <shibturn@gmail.com> | 2013-04-17 19:58:00 (GMT) |
commit | 409c31390f839debb2f05cef691e8b59e52bd524 (patch) | |
tree | 49a505458425a31be4c08e22c38c8c56c17d8992 /Lib/test/test_multiprocessing.py | |
parent | b38897fc91c7f4b80bc2025ade219674d7b78bf3 (diff) | |
download | cpython-409c31390f839debb2f05cef691e8b59e52bd524.zip cpython-409c31390f839debb2f05cef691e8b59e52bd524.tar.gz cpython-409c31390f839debb2f05cef691e8b59e52bd524.tar.bz2 |
Issue #17555: Fix ForkAwareThreadLock so that size of after fork
registry does not grow exponentially with generation of process.
Diffstat (limited to 'Lib/test/test_multiprocessing.py')
-rw-r--r-- | Lib/test/test_multiprocessing.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py index 14ec61c..9b3e180 100644 --- a/Lib/test/test_multiprocessing.py +++ b/Lib/test/test_multiprocessing.py @@ -3432,12 +3432,42 @@ class TestNoForkBomb(unittest.TestCase): self.assertEqual('', err.decode('ascii')) # +# Issue #17555: ForkAwareThreadLock +# + +class TestForkAwareThreadLock(unittest.TestCase): + # We recurisvely start processes. Issue #17555 meant that the + # after fork registry would get duplicate entries for the same + # lock. The size of the registry at generation n was ~2**n. + + @classmethod + def child(cls, n, conn): + if n > 1: + p = multiprocessing.Process(target=cls.child, args=(n-1, conn)) + p.start() + p.join() + else: + conn.send(len(util._afterfork_registry)) + conn.close() + + def test_lock(self): + r, w = multiprocessing.Pipe(False) + l = util.ForkAwareThreadLock() + old_size = len(util._afterfork_registry) + p = multiprocessing.Process(target=self.child, args=(5, w)) + p.start() + new_size = r.recv() + p.join() + self.assertLessEqual(new_size, old_size) + +# # # testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, TestStdinBadfiledescriptor, TestWait, TestInvalidFamily, - TestFlags, TestTimeouts, TestNoForkBomb] + TestFlags, TestTimeouts, TestNoForkBomb, + TestForkAwareThreadLock] # # |