bpo-33725: multiprocessing uses spawn by default on macOS (GH-13603)
On macOS, the multiprocessing module now uses the "spawn" start
method by default.
diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py
index 5a48657..5f8e0f0 100644
--- a/Lib/multiprocessing/context.py
+++ b/Lib/multiprocessing/context.py
@@ -309,7 +309,12 @@
'spawn': SpawnContext(),
'forkserver': ForkServerContext(),
}
- _default_context = DefaultContext(_concrete_contexts['fork'])
+ if sys.platform == 'darwin':
+ # bpo-33725: running arbitrary code after fork() is no longer reliable
+ # on macOS since macOS 10.14 (Mojave). Use spawn by default instead.
+ _default_context = DefaultContext(_concrete_contexts['spawn'])
+ else:
+ _default_context = DefaultContext(_concrete_contexts['fork'])
else: