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

index 7ce5af43ad713779d3e580c91dcfbaefb61a49ca,00f73a7f023360e66b4ac3b1cf5a20c10cbe9e35..56f0debee92a803e5d4cad0dc1fb14f6705c27c1
@@@ -407,14 -409,33 +409,41 @@@ class ThreadTests(BaseTestCase)
          t.daemon = True
          self.assertTrue('daemon' in repr(t))
  
 +    def test_deamon_param(self):
 +        t = threading.Thread()
 +        self.assertFalse(t.daemon)
 +        t = threading.Thread(daemon=False)
 +        self.assertFalse(t.daemon)
 +        t = threading.Thread(daemon=True)
 +        self.assertTrue(t.daemon)
 +
+     @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 197dec4fb1cbc893f7a9c592944f8ecd875053b5,58ffa7ebc2795b56d004191fb56a63296b8b7a80..8c2cee97357edff52f9e3de45754b344cbd6d880
@@@ -871,6 -1004,12 +871,9 @@@ class _DummyThread(Thread)
          with _active_limbo_lock:
              _active[self._ident] = self
  
 -    def _set_daemon(self):
 -        return True
 -
+     def _stop(self):
+         pass
      def join(self, timeout=None):
          assert False, "cannot join a dummy thread"
  
diff --cc Misc/NEWS
index 574b52be46f5dcf70689e4413ae132c3fa79f755,47d7b1097e077bde2bc3a815149398162ce8a5c8..ac5d91b6ad8cba7130bc267bf64957f21bb79a77
+++ b/Misc/NEWS
@@@ -55,12 -27,29 +55,15 @@@ Core and Builtin
  Library
  -------
  
+ - Issue #14308: Fix an exception when a "dummy" thread is in the threading
+   module's active list after a fork().
 +- Issue #11750: The Windows API functions scattered in the _subprocess and
 +  _multiprocessing.win32 modules now live in a single module "_winapi".
 +  Patch by sbt.
 +
 +- Issue #14087: multiprocessing: add Condition.wait_for(). Patch by sbt.
 +
  - Issue #14538: HTMLParser can now parse correctly start tags that contain
    a bare '/'.