Skip to content

Commit 17a5588

Browse files
authored
bpo-33725: multiprocessing uses spawn by default on macOS (GH-13603)
On macOS, the multiprocessing module now uses the "spawn" start method by default.
1 parent a85a1d3 commit 17a5588

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

Doc/library/multiprocessing.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ to start a process. These *start methods* are
102102
will not be inherited. Starting a process using this method is
103103
rather slow compared to using *fork* or *forkserver*.
104104

105-
Available on Unix and Windows. The default on Windows.
105+
Available on Unix and Windows. The default on Windows and macOS.
106106

107107
*fork*
108108
The parent process uses :func:`os.fork` to fork the Python
@@ -124,6 +124,11 @@ to start a process. These *start methods* are
124124
Available on Unix platforms which support passing file descriptors
125125
over Unix pipes.
126126

127+
.. versionchanged:: 3.8
128+
129+
On macOS, *spawn* start method is now the default: *fork* start method is no
130+
longer reliable on macOS, see :issue:`33725`.
131+
127132
.. versionchanged:: 3.4
128133
*spawn* added on all unix platforms, and *forkserver* added for
129134
some unix platforms.

Doc/whatsnew/3.8.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,16 @@ access the ``madvise()`` system call.
469469
(Contributed by Zackery Spytz in :issue:`32941`.)
470470

471471

472+
multiprocessing
473+
---------------
474+
475+
Added new :mod:`multiprocessing.shared_memory` module.
476+
(Contributed Davin Potts in :issue:`35813`.)
477+
478+
On macOS, the *spawn* start method is now used by default.
479+
(Contributed by Victor Stinner in :issue:`33725`.)
480+
481+
472482
os
473483
--
474484

Lib/multiprocessing/context.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,12 @@ def _check_available(self):
309309
'spawn': SpawnContext(),
310310
'forkserver': ForkServerContext(),
311311
}
312-
_default_context = DefaultContext(_concrete_contexts['fork'])
312+
if sys.platform == 'darwin':
313+
# bpo-33725: running arbitrary code after fork() is no longer reliable
314+
# on macOS since macOS 10.14 (Mojave). Use spawn by default instead.
315+
_default_context = DefaultContext(_concrete_contexts['spawn'])
316+
else:
317+
_default_context = DefaultContext(_concrete_contexts['fork'])
313318

314319
else:
315320

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On macOS, the :mod:`multiprocessing` module now uses *spawn* start method by
2+
default.

0 commit comments

Comments
 (0)