From: Antoine Pitrou Date: Thu, 19 Apr 2012 22:05:17 +0000 (+0200) Subject: Issue #14308: Fix an exception when a dummy thread is in the threading module's activ... X-Git-Tag: v3.3.0a3~150 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd5aa36f179011f390a0cc6fb4ba7bba1764f1a9;p=python Issue #14308: Fix an exception when a dummy thread is in the threading module's active list after a fork(). --- dd5aa36f179011f390a0cc6fb4ba7bba1764f1a9 diff --cc Lib/test/test_threading.py index 7ce5af43ad,00f73a7f02..56f0debee9 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@@ -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): diff --cc Lib/threading.py index 197dec4fb1,58ffa7ebc2..8c2cee9735 --- a/Lib/threading.py +++ b/Lib/threading.py @@@ -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 574b52be46,47d7b1097e..ac5d91b6ad --- a/Misc/NEWS +++ 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 '/'.