mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
GH-110829: Ensure Thread.join() joins the OS thread (#110848)
Joining a thread now ensures the underlying OS thread has exited. This is required for safer fork() in multi-threaded processes. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
a28a3967ab
commit
0e9c364f4a
14 changed files with 676 additions and 103 deletions
|
@ -194,11 +194,11 @@ class ProcessPoolExecutorTest(ExecutorTest):
|
|||
|
||||
context = self.get_context()
|
||||
|
||||
# gh-109047: Mock the threading.start_new_thread() function to inject
|
||||
# gh-109047: Mock the threading.start_joinable_thread() function to inject
|
||||
# RuntimeError: simulate the error raised during Python finalization.
|
||||
# Block the second creation: create _ExecutorManagerThread, but block
|
||||
# QueueFeederThread.
|
||||
orig_start_new_thread = threading._start_new_thread
|
||||
orig_start_new_thread = threading._start_joinable_thread
|
||||
nthread = 0
|
||||
def mock_start_new_thread(func, *args):
|
||||
nonlocal nthread
|
||||
|
@ -208,7 +208,7 @@ class ProcessPoolExecutorTest(ExecutorTest):
|
|||
nthread += 1
|
||||
return orig_start_new_thread(func, *args)
|
||||
|
||||
with support.swap_attr(threading, '_start_new_thread',
|
||||
with support.swap_attr(threading, '_start_joinable_thread',
|
||||
mock_start_new_thread):
|
||||
executor = self.executor_type(max_workers=2, mp_context=context)
|
||||
with executor:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue