Skip to content

Commit 285ff63

Browse files
bpo-39244: multiprocessing return default start method first on macOS (GH-18625)
(cherry picked from commit db098bc) Co-authored-by: idomic <[email protected]>
1 parent e3e800f commit 285ff63

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Lib/multiprocessing/context.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ def get_all_start_methods(self):
257257
if sys.platform == 'win32':
258258
return ['spawn']
259259
else:
260+
methods = ['spawn', 'fork'] if sys.platform == 'darwin' else ['fork', 'spawn']
260261
if reduction.HAVE_SEND_HANDLE:
261-
return ['fork', 'spawn', 'forkserver']
262-
else:
263-
return ['fork', 'spawn']
262+
methods.append('forkserver')
263+
return methods
264+
264265

265266
#
266267
# Context types for fixed start method

Lib/test/_test_multiprocessing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5007,7 +5007,9 @@ def test_get_all(self):
50075007
self.assertEqual(methods, ['spawn'])
50085008
else:
50095009
self.assertTrue(methods == ['fork', 'spawn'] or
5010-
methods == ['fork', 'spawn', 'forkserver'])
5010+
methods == ['spawn', 'fork'] or
5011+
methods == ['fork', 'spawn', 'forkserver'] or
5012+
methods == ['spawn', 'fork', 'forkserver'])
50115013

50125014
def test_preload_resources(self):
50135015
if multiprocessing.get_start_method() != 'forkserver':
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed :class:`multiprocessing.context.get_all_start_methods`
2+
to properly return the default method first on macOS.

0 commit comments

Comments
 (0)