[3.14] gh-109263: Start process from spawn context in multiprocessing no longer have side effect (GH-135813) (#143115)

gh-109263: Start process from spawn context in multiprocessing no longer have side effect (GH-135813)
(cherry picked from commit c2202a7e66)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-12-24 04:04:46 +01:00 committed by GitHub
parent e6b11c8861
commit 64461f1ca5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 1 deletions

View file

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

View file

@ -5845,6 +5845,25 @@ def test_context(self):
self.assertRaises(ValueError, ctx.set_start_method, None)
self.check_context(ctx)
@staticmethod
def _dummy_func():
pass
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')