Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/concurrent/futures/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def _python_exit():
os.register_at_fork(before=_global_shutdown_lock.acquire,
after_in_child=_global_shutdown_lock._at_fork_reinit,
after_in_parent=_global_shutdown_lock.release)
os.register_at_fork(after_in_child=_threads_queues.clear)


class WorkerContext:
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/test_concurrent_futures/test_thread_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import multiprocessing.util
import os
import threading
import warnings
import unittest
from concurrent import futures
from test import support
Expand Down Expand Up @@ -66,6 +67,25 @@ def submit(pool):
with futures.ProcessPoolExecutor(1, mp_context=mp.get_context('fork')) as workers:
workers.submit(tuple)

@support.requires_fork()
@unittest.skipUnless(hasattr(os, "register_at_fork"), "need os.register_at_fork")
@support.requires_resource("cpu")
def test_process_fork_from_a_threadpool(self):
# bpo-43944: clear concurrent.futures.thread._threads_queues after fork,
# otherwise child process will try to join parent thread
def fork_process_and_return_exitcode():
# Ignore the warning about fork with threads.
with warnings.catch_warnings(category=DeprecationWarning, action="ignore"):
p = mp.get_context("fork").Process(target=lambda: 1)
p.start()
p.join()
return p.exitcode

with futures.ThreadPoolExecutor(1) as pool:
process_exitcode = pool.submit(fork_process_and_return_exitcode).result()

self.assertEqual(process_exitcode, 0)

def test_executor_map_current_future_cancel(self):
stop_event = threading.Event()
log = []
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :class:`multiprocessing.Process` exiting with code 1 even on successful run when
threads are used in the same application too.
Loading