File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -444,6 +444,27 @@ def background_thread(evt):
444444 self .assertEqual (out , b'' )
445445 self .assertEqual (err , b'' )
446446
447+ @unittest .skipUnless (hasattr (os , 'fork' ), "needs os.fork()" )
448+ def test_is_alive_after_fork (self ):
449+ # Try hard to trigger #18418: is_alive() could sometimes be True on
450+ # threads that vanished after a fork.
451+ old_interval = sys .getswitchinterval ()
452+ self .addCleanup (sys .setswitchinterval , old_interval )
453+
454+ # Make the bug more likely to manifest.
455+ sys .setswitchinterval (1e-6 )
456+
457+ for i in range (20 ):
458+ t = threading .Thread (target = lambda : None )
459+ t .start ()
460+ self .addCleanup (t .join )
461+ pid = os .fork ()
462+ if pid == 0 :
463+ os ._exit (1 if t .is_alive () else 0 )
464+ else :
465+ pid , status = os .waitpid (pid , 0 )
466+ self .assertEqual (0 , status )
467+
447468
448469class ThreadJoinOnShutdown (BaseTestCase ):
449470
Original file line number Diff line number Diff line change @@ -935,7 +935,7 @@ def _after_fork():
935935 new_active = {}
936936 current = current_thread ()
937937 with _active_limbo_lock :
938- for thread in _active . values ():
938+ for thread in _enumerate ():
939939 # Any lock/condition variable may be currently locked or in an
940940 # invalid state, so we reinitialize them.
941941 thread ._reset_internal_locks ()
Original file line number Diff line number Diff line change @@ -279,6 +279,7 @@ Ben Darnell
279279Kushal Das
280280Jonathan Dasteel
281281Pierre-Yves David
282+ A. Jesse Jiryu Davis
282283John DeGood
283284Ned Deily
284285Vincent Delft
Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ Core and Builtins
6666Library
6767-------
6868
69+ - Issue #18418: After fork(), reinit all threads states, not only active ones.
70+ Patch by A. Jesse Jiryu Davis.
71+
6972- Issue #16611: http.cookie now correctly parses the 'secure' and 'httponly'
7073 cookie flags.
7174
You can’t perform that action at this time.
0 commit comments