-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135726: multiprocessing.freeze_support no longer sets the start method globally. #135810
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
base: main
Are you sure you want to change the base?
Conversation
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.
Could you come up with a meaningful regression test for this?
Lib/multiprocessing/context.py
Outdated
start_method = self.get_start_method(allow_none=True) | ||
if start_method is None: | ||
start_method = self._default_context.get_start_method() | ||
if start_method == 'spawn' and getattr(sys, 'frozen', False): |
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.
Rather than adding this method to DefaultContext, which complicates the picture of which one is called when and why two are defined in the heirarchy, perhaps edit the one in BaseContext to something like this:
diff --git a/Lib/multiprocessing/context.py b/Lib/multiprocessing/context.py
index 051d567d457..2d5c9a1d3dd 100644
--- a/Lib/multiprocessing/context.py
+++ b/Lib/multiprocessing/context.py
@@ -145,7 +145,11 @@ def freeze_support(self):
'''Check whether this is a fake forked process in a frozen executable.
If so then run code specified by commandline and exit.
'''
- if self.get_start_method() == 'spawn' and getattr(sys, 'frozen', False):
+ # GH-135726: allow_none=True prevents this "get" call from setting the
+ # default context as the selected one as a side-effect.
+ if (getattr(sys, 'frozen', False) and
+ isinstance(self.get_start_method(allow_none=True)
+ or _default_context, SpawnContext)):
from .spawn import freeze_support
freeze_support()
(untested - I'm just trying to reason though the logic)
Thank you for the review, updated! |
@aisk This second commit will not break the patches I already have in use in cx_Freeze, because I monkeypatched freeze_support. And it does not interfere with the start method in Python (since it is not frozen). On Windows, this should work as it was before the PR that caused the regression. On Linux and macOS, I will continue monkeypatching until the gh-76327 is applied. |
Uh oh!
There was an error while loading. Please reload this page.