Skip to content

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

Merged
merged 14 commits into from
May 26, 2020

Conversation

idomic
Copy link
Contributor

@idomic idomic commented Feb 23, 2020

@idomic
Copy link
Contributor Author

idomic commented Feb 23, 2020

@taleinat clean PR

@codecov
Copy link

codecov bot commented Feb 23, 2020

Codecov Report

Merging #18625 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) ⬇️
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) ⬇️
Modules/_decimal/libmpdec/umodarith.h 80.76% <0.00%> (-19.24%) ⬇️
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) ⬇️
Lib/test/test_smtpnet.py 78.57% <0.00%> (-7.15%) ⬇️
Lib/ftplib.py 63.85% <0.00%> (-6.06%) ⬇️
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) ⬇️
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) ⬇️
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) ⬇️
Lib/test/test_socket.py 71.94% <0.00%> (-3.77%) ⬇️
... and 321 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b76518d...33db325. Read the comment docs.

@idomic
Copy link
Contributor Author

idomic commented Mar 1, 2020

Adding @taleinat , do I have to add tests for this?

@idomic
Copy link
Contributor Author

idomic commented Mar 15, 2020

ping @taleinat

@@ -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
Contributor

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?

Copy link
Contributor Author

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

@taleinat
Copy link
Contributor

Adding @taleinat , do I have to add tests for this?

The test already included seems sufficient.

@taleinat
Copy link
Contributor

ping @taleinat

Sorry, I'm extremely busy these days...

@idomic
Copy link
Contributor Author

idomic commented Mar 22, 2020

ping @taleinat

Sorry, I'm extremely busy these days...

That's alright, don't worry about it and stay safe!

@@ -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':
Copy link
Contributor

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.

@@ -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'])
Copy link
Contributor

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.

Copy link
Contributor Author

@idomic idomic May 17, 2020

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

@bedevere-bot
Copy link

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. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@idomic
Copy link
Contributor Author

idomic commented May 24, 2020

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from taleinat May 24, 2020 23:07
@@ -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']
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@bedevere-bot
Copy link

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. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Comment on lines 260 to 263
if reduction.HAVE_SEND_HANDLE:
return ['fork', 'spawn', 'forkserver']
else:
return ['fork', 'spawn']
if sys.platform == 'darwin':
return ['spawn', 'fork', 'forkserver']
Copy link
Contributor

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.

Suggested change
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

Copy link
Contributor

@taleinat taleinat left a comment

Choose a reason for hiding this comment

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

LGTM

@taleinat taleinat added the needs backport to 3.9 only security fixes label May 26, 2020
@taleinat taleinat merged commit db098bc into python:master May 26, 2020
@miss-islington
Copy link
Contributor

Thanks @idomic for the PR, and @taleinat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-20431 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 26, 2020
@bedevere-bot
Copy link

GH-20432 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request May 26, 2020
miss-islington added a commit that referenced this pull request May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants