]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109263: Start process from spawn context in multiprocessing no longer have side...
authorAN Long <aisk@users.noreply.github.com>
Tue, 23 Dec 2025 19:28:32 +0000 (04:28 +0900)
committerGitHub <noreply@github.com>
Tue, 23 Dec 2025 19:28:32 +0000 (19:28 +0000)
Lib/multiprocessing/spawn.py
Lib/test/_test_multiprocessing.py
Misc/NEWS.d/next/Library/2025-06-22-18-57-19.gh-issue-109263.f92V95.rst [new file with mode: 0644]

index daac1ecc34b55ecd582d8571ea4083769b884870..d43864c939cb63faae44ef68c9d6f9d30dc0dbe0 100644 (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
index d03eb1dfb253ec32e6aab18acccc48eb01a6d6f4..c8c386101a0669012f5c7c1d2b47c66b5dd81469 100644 (file)
@@ -5967,6 +5967,26 @@ class TestStartMethod(unittest.TestCase):
             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')
diff --git a/Misc/NEWS.d/next/Library/2025-06-22-18-57-19.gh-issue-109263.f92V95.rst b/Misc/NEWS.d/next/Library/2025-06-22-18-57-19.gh-issue-109263.f92V95.rst
new file mode 100644 (file)
index 0000000..6b96b5b
--- /dev/null
@@ -0,0 +1,2 @@
+Starting a process from spawn context in :mod:`multiprocessing` no longer
+sets the start method globally.