]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #874900: fix behaviour of threading module after a fork.
authorAntoine Pitrou <solipsis@pitrou.net>
Sat, 6 Sep 2008 23:00:03 +0000 (23:00 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sat, 6 Sep 2008 23:00:03 +0000 (23:00 +0000)
Reviewed by Gregory P. Smith.

Lib/test/test_threading.py
Lib/threading.py
Misc/NEWS

index 775e312667235b53a9a13eafc1013a1cffd4e9eb..a7f232270662cef93d5d501689f8c088d2b1383a 100644 (file)
@@ -347,6 +347,9 @@ class ThreadJoinOnShutdown(unittest.TestCase):
             def joiningfunc(mainthread):
                 mainthread.join()
                 print('end of thread')
+                # stdout is fully buffered because not a tty, we have to flush
+                # before exit.
+                sys.stdout.flush()
         \n""" + script
 
         import subprocess
@@ -388,8 +391,7 @@ class ThreadJoinOnShutdown(unittest.TestCase):
             """
         self._run_and_join(script)
 
-    # XXX This test hangs!
-    def Xtest_3_join_in_forked_from_thread(self):
+    def test_3_join_in_forked_from_thread(self):
         # Like the test above, but fork() was called from a worker thread
         # In the forked process, the main Thread object must be marked as stopped.
         import os
index 1d59cb0f1e4fafcd4666e1e58fbce85111486fe2..b541d77ca2b7e4499524e7eeaabaffed76cd262e 100644 (file)
@@ -835,16 +835,19 @@ def _after_fork():
     new_active = {}
     current = current_thread()
     with _active_limbo_lock:
-        for ident, thread in _active.items():
+        for thread in _active.values():
             if thread is current:
-                # There is only one active thread.
+                # There is only one active thread. We reset the ident to
+                # its new value since it can have changed.
+                ident = _get_ident()
+                thread._ident = ident
                 new_active[ident] = thread
             else:
                 # All the others are already stopped.
                 # We don't call _Thread__stop() because it tries to acquire
                 # thread._Thread__block which could also have been held while
                 # we forked.
-                thread._Thread__stopped = True
+                thread._stopped = True
 
         _limbo.clear()
         _active.clear()
index ef860a4cc602a638cd332657506d75b1e01e10a4..cacbef47806386959c269bd1c18d39d226a57391 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -90,6 +90,8 @@ C API
 Library
 -------
 
+- Issue #874900: fix behaviour of threading module after a fork.
+
 - Issue #3535: zipfile couldn't read some zip files larger than 2GB.
 
 - Issue #3776: Deprecate the bsddb package for removal in 3.0.