MCPcopy Index your code
hub / github.com/python/cpython / test_is_alive_after_fork

Method test_is_alive_after_fork

Lib/test/test_threading.py:734–754  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

732
733 @skip_unless_reliable_fork
734 def test_is_alive_after_fork(self):
735 # Try hard to trigger #18418: is_alive() could sometimes be True on
736 # threads that vanished after a fork.
737 old_interval = sys.getswitchinterval()
738 self.addCleanup(sys.setswitchinterval, old_interval)
739
740 # Make the bug more likely to manifest.
741 test.support.setswitchinterval(1e-6)
742
743 for i in range(20):
744 t = threading.Thread(target=lambda: None)
745 t.start()
746 # Ignore the warning about fork with threads.
747 with warnings.catch_warnings(category=DeprecationWarning,
748 action="ignore"):
749 if (pid := os.fork()) == 0:
750 os._exit(11 if t.is_alive() else 10)
751 else:
752 t.join()
753
754 support.wait_process(pid, exitcode=10)
755
756 def test_main_thread(self):
757 main = threading.main_thread()

Callers

nothing calls this directly

Calls 5

startMethod · 0.95
is_aliveMethod · 0.95
joinMethod · 0.95
addCleanupMethod · 0.80
_exitMethod · 0.45

Tested by

no test coverage detected