]> granicus.if.org Git - python/commitdiff
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's...
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 19 Apr 2012 21:55:01 +0000 (23:55 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 19 Apr 2012 21:55:01 +0000 (23:55 +0200)
Lib/test/test_threading.py
Lib/threading.py
Misc/NEWS

index dfc0ddf49c8843e5390d422a5d799b59493c8ffb..00f73a7f023360e66b4ac3b1cf5a20c10cbe9e35 100644 (file)
@@ -2,6 +2,8 @@
 
 import test.support
 from test.support import verbose, strip_python_stderr, import_module
+from test.script_helper import assert_python_ok
+
 import random
 import re
 import sys
@@ -407,6 +409,33 @@ class ThreadTests(BaseTestCase):
         t.daemon = True
         self.assertTrue('daemon' in repr(t))
 
+    @unittest.skipUnless(hasattr(os, 'fork'), 'test needs fork()')
+    def test_dummy_thread_after_fork(self):
+        # Issue #14308: a dummy thread in the active list doesn't mess up
+        # the after-fork mechanism.
+        code = """if 1:
+            import _thread, threading, os, time
+
+            def background_thread(evt):
+                # Creates and registers the _DummyThread instance
+                threading.current_thread()
+                evt.set()
+                time.sleep(10)
+
+            evt = threading.Event()
+            _thread.start_new_thread(background_thread, (evt,))
+            evt.wait()
+            assert threading.active_count() == 2, threading.active_count()
+            if os.fork() == 0:
+                assert threading.active_count() == 1, threading.active_count()
+                os._exit(0)
+            else:
+                os.wait()
+        """
+        _, out, err = assert_python_ok("-c", code)
+        self.assertEqual(out, b'')
+        self.assertEqual(err, b'')
+
 
 class ThreadJoinOnShutdown(BaseTestCase):
 
index 69b7763c8ac8e1b2146c9bb7513473fa95fd11df..58ffa7ebc2795b56d004191fb56a63296b8b7a80 100644 (file)
@@ -1007,6 +1007,9 @@ class _DummyThread(Thread):
     def _set_daemon(self):
         return True
 
+    def _stop(self):
+        pass
+
     def join(self, timeout=None):
         assert False, "cannot join a dummy thread"
 
index b012d28467a1c719e2d57c78185f21f08e2d37df..47d7b1097e077bde2bc3a815149398162ce8a5c8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -47,6 +47,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14308: Fix an exception when a "dummy" thread is in the threading
+  module's active list after a fork().
+
 - Issue #14538: HTMLParser can now parse correctly start tags that contain
   a bare '/'.