diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index 695f7733305ed7..6acac6f80dc448 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -640,10 +640,6 @@ def __init__(self, max_workers=None, mp_context=None, self._max_workers = max_workers - if mp_context is None: - mp_context = mp.get_context() - self._mp_context = mp_context - if initializer is not None and not callable(initializer): raise TypeError("initializer must be a callable") self._initializer = initializer @@ -654,8 +650,16 @@ def __init__(self, max_workers=None, mp_context=None, raise TypeError("max_tasks_per_child must be an integer") elif max_tasks_per_child <= 0: raise ValueError("max_tasks_per_child must be >= 1") + if mp_context is None: + mp_context = mp.get_context("spawn") + if mp_context._name == "fork": + raise ValueError("max_tasks_per_child cannot be used with a fork context") self._max_tasks_per_child = max_tasks_per_child + if mp_context is None: + mp_context = mp.get_context() + self._mp_context = mp_context + # Management thread self._executor_manager_thread = None diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-03-29-21-33-41.bpo-44733.VbHuf9.rst b/Misc/NEWS.d/next/Core and Builtins/2022-03-29-21-33-41.bpo-44733.VbHuf9.rst new file mode 100644 index 00000000000000..43111d4b5cc857 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-03-29-21-33-41.bpo-44733.VbHuf9.rst @@ -0,0 +1 @@ +Ensured that ``max_tasks_per_child`` is not used with a fork context.