diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-19 22:05:17 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-04-19 22:05:17 (GMT) |
commit | dd5aa36f179011f390a0cc6fb4ba7bba1764f1a9 (patch) | |
tree | 8eab78b2d8fe17426fe8bc2dca0b33628920a750 /Lib | |
parent | bf35c156b48bd09febeb74d0a5b218e959d4225b (diff) | |
parent | 8e6e0fdb7fee3796df8b578c1311b5e46005f2d9 (diff) | |
download | cpython-dd5aa36f179011f390a0cc6fb4ba7bba1764f1a9.zip cpython-dd5aa36f179011f390a0cc6fb4ba7bba1764f1a9.tar.gz cpython-dd5aa36f179011f390a0cc6fb4ba7bba1764f1a9.tar.bz2 |
Issue #14308: Fix an exception when a dummy thread is in the threading module's active list after a fork().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_threading.py | 29 | ||||
-rw-r--r-- | Lib/threading.py | 3 |
2 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 7ce5af4..56f0deb 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -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 @@ -415,6 +417,33 @@ class ThreadTests(BaseTestCase): 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 --git a/Lib/threading.py b/Lib/threading.py index 197dec4..8c2cee9 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -871,6 +871,9 @@ class _DummyThread(Thread): with _active_limbo_lock: _active[self._ident] = self + def _stop(self): + pass + def join(self, timeout=None): assert False, "cannot join a dummy thread" |