diff options
author | Gregory P. Smith <greg@krypto.org> | 2024-09-26 23:57:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 23:57:19 (GMT) |
commit | b65f2cdfa77d8d12c213aec663ddaaa30d75a4b2 (patch) | |
tree | 995b44874413c1753fb8cdae59fc5f795e52c1a1 /Lib/multiprocessing/context.py | |
parent | 83e5dc0f4d0d8d71288f162840b36f210fb03abf (diff) | |
download | cpython-b65f2cdfa77d8d12c213aec663ddaaa30d75a4b2.zip cpython-b65f2cdfa77d8d12c213aec663ddaaa30d75a4b2.tar.gz cpython-b65f2cdfa77d8d12c213aec663ddaaa30d75a4b2.tar.bz2 |
gh-84559: Change the multiprocessing start method default to `forkserver` (GH-101556)
Change the default multiprocessing start method away from fork to forkserver or spawn on the remaining platforms where it was fork. See the issue for context. This makes the default far more thread safe (other than for people spawning threads at import time... - don't do that!).
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Diffstat (limited to 'Lib/multiprocessing/context.py')
-rw-r--r-- | Lib/multiprocessing/context.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py index ddcc7e7..d0a3ad0 100644 --- a/Lib/multiprocessing/context.py +++ b/Lib/multiprocessing/context.py @@ -259,13 +259,12 @@ class DefaultContext(BaseContext): def get_all_start_methods(self): """Returns a list of the supported start methods, default first.""" - if sys.platform == 'win32': - return ['spawn'] - else: - methods = ['spawn', 'fork'] if sys.platform == 'darwin' else ['fork', 'spawn'] - if reduction.HAVE_SEND_HANDLE: - methods.append('forkserver') - return methods + default = self._default_context.get_start_method() + start_method_names = [default] + start_method_names.extend( + name for name in _concrete_contexts if name != default + ) + return start_method_names # @@ -320,14 +319,15 @@ if sys.platform != 'win32': 'spawn': SpawnContext(), 'forkserver': ForkServerContext(), } - 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']) + # bpo-33725: running arbitrary code after fork() is no longer reliable + # on macOS since macOS 10.14 (Mojave). Use spawn by default instead. + # gh-84559: We changed everyones default to a thread safeish one in 3.14. + if reduction.HAVE_SEND_HANDLE and sys.platform != 'darwin': + _default_context = DefaultContext(_concrete_contexts['forkserver']) else: - _default_context = DefaultContext(_concrete_contexts['fork']) + _default_context = DefaultContext(_concrete_contexts['spawn']) -else: +else: # Windows class SpawnProcess(process.BaseProcess): _start_method = 'spawn' |