]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-146004: propagate all -X options to multiprocessing child processes (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 28 Mar 2026 05:30:06 +0000 (06:30 +0100)
committerGitHub <noreply@github.com>
Sat, 28 Mar 2026 05:30:06 +0000 (05:30 +0000)
gh-146004: propagate all -X options to multiprocessing child processes (GH-146005)

Propagate all -X command line options to multiprocessing spawned child Python processes.
(cherry picked from commit 1efe441de7c448852b9ba51fb0db4d355a7157a8)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Lib/subprocess.py
Lib/test/test_support.py
Misc/NEWS.d/next/Library/2026-03-16-00-00-00.gh-issue-146004.xOptProp.rst [new file with mode: 0644]

index 578d7b95d05d7b5d4e97a6ffa9b1b5e415e83f1a..52b7b7117703d71e835a90af45b54faa567bacd9 100644 (file)
@@ -351,15 +351,16 @@ def _args_from_interpreter_flags():
     # -X options
     if dev_mode:
         args.extend(('-X', 'dev'))
-    for opt in ('faulthandler', 'tracemalloc', 'importtime',
-                'frozen_modules', 'showrefcount', 'utf8', 'gil'):
-        if opt in xoptions:
-            value = xoptions[opt]
-            if value is True:
-                arg = opt
-            else:
-                arg = '%s=%s' % (opt, value)
-            args.extend(('-X', arg))
+    for opt in sorted(xoptions):
+        if opt == 'dev':
+            # handled above via sys.flags.dev_mode
+            continue
+        value = xoptions[opt]
+        if value is True:
+            arg = opt
+        else:
+            arg = '%s=%s' % (opt, value)
+        args.extend(('-X', arg))
 
     return args
 
index 79f0e2eb29ff4cac45a4fc29a5aec0eb8f8686e8..97db7405a8bbef915d1bed5db1322a630f400d6f 100644 (file)
@@ -559,12 +559,19 @@ class TestSupport(unittest.TestCase):
             # -X options
             ['-X', 'dev'],
             ['-Wignore', '-X', 'dev'],
+            ['-X', 'cpu_count=4'],
+            ['-X', 'disable-remote-debug'],
             ['-X', 'faulthandler'],
             ['-X', 'importtime'],
             ['-X', 'importtime=2'],
+            ['-X', 'int_max_str_digits=1000'],
+            ['-X', 'lazy_imports=all'],
+            ['-X', 'no_debug_ranges'],
+            ['-X', 'pycache_prefix=/tmp/pycache'],
             ['-X', 'showrefcount'],
             ['-X', 'tracemalloc'],
             ['-X', 'tracemalloc=3'],
+            ['-X', 'warn_default_encoding'],
         ):
             with self.subTest(opts=opts):
                 self.check_options(opts, 'args_from_interpreter_flags')
diff --git a/Misc/NEWS.d/next/Library/2026-03-16-00-00-00.gh-issue-146004.xOptProp.rst b/Misc/NEWS.d/next/Library/2026-03-16-00-00-00.gh-issue-146004.xOptProp.rst
new file mode 100644 (file)
index 0000000..234e610
--- /dev/null
@@ -0,0 +1,9 @@
+All :option:`-X` options from the Python command line are now propagated to
+child processes spawned by :mod:`multiprocessing`, not just a hard-coded
+subset.  This makes the behavior consistent between default "spawn" and
+"forkserver" start methods and the old "fork" start method.  The options
+that were previously not propagated are: ``context_aware_warnings``,
+``cpu_count``, ``disable-remote-debug``, ``int_max_str_digits``,
+``lazy_imports``, ``no_debug_ranges``, ``pathconfig_warnings``, ``perf``,
+``perf_jit``, ``presite``, ``pycache_prefix``, ``thread_inherit_context``,
+and ``warn_default_encoding``.