Skip to content

Commit bf52bfa

Browse files
bpo-44733: max_tasks_per_child + fork not allowed
1 parent 63f32fa commit bf52bfa

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Lib/concurrent/futures/process.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,6 @@ def __init__(self, max_workers=None, mp_context=None,
640640

641641
self._max_workers = max_workers
642642

643-
if mp_context is None:
644-
mp_context = mp.get_context()
645-
self._mp_context = mp_context
646-
647643
if initializer is not None and not callable(initializer):
648644
raise TypeError("initializer must be a callable")
649645
self._initializer = initializer
@@ -654,8 +650,16 @@ def __init__(self, max_workers=None, mp_context=None,
654650
raise TypeError("max_tasks_per_child must be an integer")
655651
elif max_tasks_per_child <= 0:
656652
raise ValueError("max_tasks_per_child must be >= 1")
653+
if mp_context is None:
654+
mp_context = mp.get_context("spawn")
655+
if mp_context._name == "fork":
656+
raise ValueError("max_tasks_per_child cannot be used with a fork context")
657657
self._max_tasks_per_child = max_tasks_per_child
658658

659+
if mp_context is None:
660+
mp_context = mp.get_context()
661+
self._mp_context = mp_context
662+
659663
# Management thread
660664
self._executor_manager_thread = None
661665

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensured that ``max_tasks_per_child`` is not used with a fork context.

0 commit comments

Comments
 (0)