-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-39244: multiprocessing get all start methods #18625
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
Conversation
@taleinat clean PR |
Codecov Report
@@ Coverage Diff @@
## master #18625 +/- ##
==========================================
- Coverage 82.11% 82.06% -0.05%
==========================================
Files 1956 1955 -1
Lines 589428 584089 -5339
Branches 44459 44461 +2
==========================================
- Hits 484010 479356 -4654
+ Misses 95762 95105 -657
+ Partials 9656 9628 -28
Continue to review full report at Codecov.
|
Adding @taleinat , do I have to add tests for this? |
ping @taleinat |
Lib/multiprocessing/context.py
Outdated
@@ -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'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this not require the if reduction.HAVE_SEND_HANDLE:
check as below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the platform check to be included in the HAVE_SEND_HANDLE if block
The test already included seems sufficient. |
Sorry, I'm extremely busy these days... |
That's alright, don't worry about it and stay safe! |
…bpo-39244_multiprocessing
Lib/multiprocessing/context.py
Outdated
@@ -258,7 +258,10 @@ def get_all_start_methods(self): | |||
return ['spawn'] | |||
else: | |||
if reduction.HAVE_SEND_HANDLE: | |||
return ['fork', 'spawn', 'forkserver'] | |||
if sys.platform == 'darwin': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you certain reduction.HAVE_SEND_HANDLE
will always be true on macOS? If not 100% this is true on older and future versions, then a similar change should be done in the else
clause below.
Lib/test/_test_multiprocessing.py
Outdated
@@ -5022,6 +5022,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']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ISTM this should allow 'forkserver' to be missing, as done by the assertion two lines below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped this test, I agree it's redundant + fixed the code to have the return value in the else clause
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again |
Thanks for making the requested changes! @taleinat: please review the changes made to this pull request. |
Lib/multiprocessing/context.py
Outdated
@@ -257,10 +257,11 @@ def get_all_start_methods(self): | |||
if sys.platform == 'win32': | |||
return ['spawn'] | |||
else: | |||
if sys.platform == 'darwin': | |||
return ['spawn', 'fork', 'forkserver'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the intention of the existing code: The purpose of the HAVE_SEND_HANDLE
check is to decide whether to include 'forkserver' as an option. It should be done regardless of platform.
Perhaps just add a conditional after this code the brings 'spawn' to the beginning of the list on macOS.
@@ -0,0 +1,2 @@ | |||
Fixed :class:`multiprocessing.context.get_all_start_methods` | |||
If the context is macOS, return the default methods by order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wording is imprecise; this should always return the default method first, which was not done on the macOS platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Lib/multiprocessing/context.py
Outdated
if reduction.HAVE_SEND_HANDLE: | ||
return ['fork', 'spawn', 'forkserver'] | ||
else: | ||
return ['fork', 'spawn'] | ||
if sys.platform == 'darwin': | ||
return ['spawn', 'fork', 'forkserver'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to return a list without 'forkserver' when HAVE_SEND_HANDLE
is false.
if reduction.HAVE_SEND_HANDLE: | |
return ['fork', 'spawn', 'forkserver'] | |
else: | |
return ['fork', 'spawn'] | |
if sys.platform == 'darwin': | |
return ['spawn', 'fork', 'forkserver'] | |
methods = ['spawn', 'fork'] if sys.platform == 'darwin' else ['fork', 'spawn'] | |
if reduction.HAVE_SEND_HANDLE: | |
methods.append('forkserver') | |
return methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
GH-20431 is a backport of this pull request to the 3.9 branch. |
…pythonGH-18625) (cherry picked from commit db098bc) Co-authored-by: idomic <[email protected]>
GH-20432 is a backport of this pull request to the 3.8 branch. |
…GH-18625) (cherry picked from commit db098bc) Co-authored-by: idomic <[email protected]>
…GH-18625) (cherry picked from commit db098bc) Co-authored-by: idomic <[email protected]>
https://bugs.python.org/issue39244