mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #18418: After fork(), reinit all threads states, not only active ones.
Patch by A. Jesse Jiryu Davis.
This commit is contained in:
commit
79a53ea7d7
4 changed files with 26 additions and 1 deletions
|
@ -445,6 +445,27 @@ class ThreadTests(BaseTestCase):
|
||||||
self.assertEqual(out, b'')
|
self.assertEqual(out, b'')
|
||||||
self.assertEqual(err, 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):
|
class ThreadJoinOnShutdown(BaseTestCase):
|
||||||
|
|
||||||
|
|
|
@ -940,7 +940,7 @@ def _after_fork():
|
||||||
new_active = {}
|
new_active = {}
|
||||||
current = current_thread()
|
current = current_thread()
|
||||||
with _active_limbo_lock:
|
with _active_limbo_lock:
|
||||||
for thread in _active.values():
|
for thread in _enumerate():
|
||||||
# Any lock/condition variable may be currently locked or in an
|
# Any lock/condition variable may be currently locked or in an
|
||||||
# invalid state, so we reinitialize them.
|
# invalid state, so we reinitialize them.
|
||||||
thread._reset_internal_locks()
|
thread._reset_internal_locks()
|
||||||
|
|
|
@ -288,6 +288,7 @@ Ben Darnell
|
||||||
Kushal Das
|
Kushal Das
|
||||||
Jonathan Dasteel
|
Jonathan Dasteel
|
||||||
Pierre-Yves David
|
Pierre-Yves David
|
||||||
|
A. Jesse Jiryu Davis
|
||||||
John DeGood
|
John DeGood
|
||||||
Ned Deily
|
Ned Deily
|
||||||
Vincent Delft
|
Vincent Delft
|
||||||
|
|
|
@ -51,6 +51,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #18418: After fork(), reinit all threads states, not only active ones.
|
||||||
|
Patch by A. Jesse Jiryu Davis.
|
||||||
|
|
||||||
- Issue #17974: Switch unittest from using getopt to using argparse.
|
- Issue #17974: Switch unittest from using getopt to using argparse.
|
||||||
|
|
||||||
- Issue #11798: TestSuite now drops references to own tests after execution.
|
- Issue #11798: TestSuite now drops references to own tests after execution.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue