summaryrefslogtreecommitdiff
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorCharles-Fran?ois Natali <cf.natali@gmail.com>2013-08-30 23:32:53 +0200
committerCharles-Fran?ois Natali <cf.natali@gmail.com>2013-08-30 23:32:53 +0200
commit47072a04d25452e633e53713009e9a65fe3fc099 (patch)
tree2ac9dcc2ddf6c9929eead6061b32bafd396afe87 /Lib/test/test_threading.py
parente89b9633a5d7e20a617195d34475d494136837f0 (diff)
downloadcpython-47072a04d25452e633e53713009e9a65fe3fc099.tar.gz
Issue #18418: After fork(), reinit all threads states, not only active ones.
Patch by A. Jesse Jiryu Davis.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 79967dc0cf..bd019cddd3 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -444,6 +444,27 @@ class ThreadTests(BaseTestCase):
self.assertEqual(out, b'')
self.assertEqual(err, b'')
+ @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.getswitchinterval()
+ self.addCleanup(sys.setswitchinterval, old_interval)
+
+ # Make the bug more likely to manifest.
+ sys.setswitchinterval(1e-6)
+
+ for i in range(20):
+ t = threading.Thread(target=lambda: None)
+ t.start()
+ self.addCleanup(t.join)
+ pid = os.fork()
+ if pid == 0:
+ os._exit(1 if t.is_alive() else 0)
+ else:
+ pid, status = os.waitpid(pid, 0)
+ self.assertEqual(0, status)
+
class ThreadJoinOnShutdown(BaseTestCase):