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
2 changes: 1 addition & 1 deletion Lib/multiprocessing/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def get_preparation_data(name):
sys_argv=sys.argv,
orig_dir=process.ORIGINAL_DIR,
dir=os.getcwd(),
start_method=get_start_method(),
start_method=get_start_method(allow_none=True),
)

# Figure out whether to initialise main in the subprocess as a module
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5932,6 +5932,26 @@ def test_context(self):
self.assertRaises(ValueError, ctx.set_start_method, None)
self.check_context(ctx)

@staticmethod
def _dummy_func():
pass

@warnings_helper.ignore_fork_in_thread_deprecation_warnings()
def test_spawn_dont_set_context(self):
# Run a process with spawn or forkserver context may change
# the global start method, see gh-109263.
for method in ('fork', 'spawn', 'forkserver'):
multiprocessing.set_start_method(None, force=True)

try:
ctx = multiprocessing.get_context(method)
except ValueError:
continue
process = ctx.Process(target=self._dummy_func)
process.start()
process.join()
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 @@
Starting a process from spawn context in :mod:`multiprocessing` no longer
sets the start method globally.
Loading