diff options
author | Charles-François Natali <cf.natali@gmail.com> | 2013-08-30 21:30:50 (GMT) |
---|---|---|
committer | Charles-François Natali <cf.natali@gmail.com> | 2013-08-30 21:30:50 (GMT) |
commit | 30a5445b30bb627a64b2d30788f6db58f6db3ae1 (patch) | |
tree | e2c1e80823eca78cc037775f2a7a4823797e9112 /Lib/test | |
parent | b2fa280e9e1da3724a81f47a4659cc3526d95a96 (diff) | |
download | cpython-30a5445b30bb627a64b2d30788f6db58f6db3ae1.zip cpython-30a5445b30bb627a64b2d30788f6db58f6db3ae1.tar.gz cpython-30a5445b30bb627a64b2d30788f6db58f6db3ae1.tar.bz2 |
Issue #18418: After fork(), reinit all threads states, not only active ones.
Patch by A. Jesse Jiryu Davis.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_threading.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index ef04cd3..5a765f3 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -443,6 +443,29 @@ class ThreadTests(BaseTestCase): self.assertEqual(out, '') self.assertEqual(err, '') + @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") + def test_is_alive_after_fork(self): + # Try hard to trigger #18418: is_alive() could sometimes be True on + # threads that vanished after a fork. + old_interval = sys.getcheckinterval() + + # Make the bug more likely to manifest. + sys.setcheckinterval(10) + + try: + for i in range(20): + t = threading.Thread(target=lambda: None) + t.start() + pid = os.fork() + if pid == 0: + os._exit(1 if t.is_alive() else 0) + else: + t.join() + pid, status = os.waitpid(pid, 0) + self.assertEqual(0, status) + finally: + sys.setcheckinterval(old_interval) + class ThreadJoinOnShutdown(BaseTestCase): |