Skip to content

bpo-39244: multiprocessing get all start methods #18529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/multiprocessing/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def get_start_method(self, allow_none=False):
def get_all_start_methods(self):
if sys.platform == 'win32':
return ['spawn']
elif sys.platform == 'darwin':
return ['spawn', 'fork', 'forkserver']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is HAVE_SEND_HANDLE guaranteed to be defined on macOS?

Copy link
Contributor Author

@idomic idomic Feb 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's always set from a certain version (could not find documentation for that), the example of the code that defaults to this case and to 'fork' is in the bugs.python.

else:
if reduction.HAVE_SEND_HANDLE:
return ['fork', 'spawn', 'forkserver']
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4982,6 +4982,8 @@ def test_get_all(self):
methods = multiprocessing.get_all_start_methods()
if sys.platform == 'win32':
self.assertEqual(methods, ['spawn'])
elif sys.platform == 'darwin':
self.assertEqual(methods, ['spawn', 'fork', 'forkserver'])
else:
self.assertTrue(methods == ['fork', 'spawn'] or
methods == ['fork', 'spawn', 'forkserver'])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed default :class:`multiprocessing.context` in :func:`get_all_start_methods`
if the context is macOS, return the default 'spawn'