Skip to content
Open
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
15 changes: 12 additions & 3 deletions Lib/multiprocessing/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,18 @@ 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):
from .spawn import freeze_support
freeze_support()
if not getattr(sys, 'frozen', False):
return

# GH-135726: allow_none=True prevents this "get" call from setting the
# default context as the selected one as a side-effect.
method = (self.get_start_method(allow_none=True)
or _default_context.get_start_method(allow_none=True))
if method != "spawn":
return

from .spawn import freeze_support
freeze_support()

def get_logger(self):
'''Return package logger -- if it does not already exist then
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5932,6 +5932,13 @@ def test_context(self):
self.assertRaises(ValueError, ctx.set_start_method, None)
self.check_context(ctx)

def test_freeze_support_side_effect(self):
# GH-135726: freeze_support() should not set the start method
# as a side-feect,
multiprocessing.set_start_method(None, force=True)
multiprocessing.freeze_support()
self.assertIsNone(multiprocessing.get_start_method(allow_none=True))

def test_context_check_module_types(self):
try:
ctx = multiprocessing.get_context('forkserver')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`multiprocessing.freeze_support` no longer sets the start method
globally.
Loading