mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork().
This commit is contained in:
parent
c45868ec69
commit
52849bfaa3
3 changed files with 36 additions and 0 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
import test.test_support
|
||||
from test.test_support import verbose
|
||||
from test.script_helper import assert_python_ok
|
||||
|
||||
import random
|
||||
import re
|
||||
import sys
|
||||
|
@ -414,6 +416,33 @@ class ThreadTests(BaseTestCase):
|
|||
msg=('%d references still around' %
|
||||
sys.getrefcount(weak_raising_cyclic_object())))
|
||||
|
||||
@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, '')
|
||||
self.assertEqual(err, '')
|
||||
|
||||
|
||||
class ThreadJoinOnShutdown(BaseTestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue