Skip to content

Commit 1efe441

Browse files
authored
gh-146004: propagate all -X options to multiprocessing child processes (GH-146005)
Propagate all -X command line options to multiprocessing spawned child Python processes.
1 parent 5992238 commit 1efe441

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

Lib/subprocess.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,16 @@ def _args_from_interpreter_flags():
351351
# -X options
352352
if dev_mode:
353353
args.extend(('-X', 'dev'))
354-
for opt in ('faulthandler', 'tracemalloc', 'importtime',
355-
'frozen_modules', 'showrefcount', 'utf8', 'gil'):
356-
if opt in xoptions:
357-
value = xoptions[opt]
358-
if value is True:
359-
arg = opt
360-
else:
361-
arg = '%s=%s' % (opt, value)
362-
args.extend(('-X', arg))
354+
for opt in sorted(xoptions):
355+
if opt == 'dev':
356+
# handled above via sys.flags.dev_mode
357+
continue
358+
value = xoptions[opt]
359+
if value is True:
360+
arg = opt
361+
else:
362+
arg = '%s=%s' % (opt, value)
363+
args.extend(('-X', arg))
363364

364365
return args
365366

Lib/test/test_support.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,19 @@ def test_args_from_interpreter_flags(self):
569569
# -X options
570570
['-X', 'dev'],
571571
['-Wignore', '-X', 'dev'],
572+
['-X', 'cpu_count=4'],
573+
['-X', 'disable-remote-debug'],
572574
['-X', 'faulthandler'],
573575
['-X', 'importtime'],
574576
['-X', 'importtime=2'],
577+
['-X', 'int_max_str_digits=1000'],
578+
['-X', 'lazy_imports=all'],
579+
['-X', 'no_debug_ranges'],
580+
['-X', 'pycache_prefix=/tmp/pycache'],
575581
['-X', 'showrefcount'],
576582
['-X', 'tracemalloc'],
577583
['-X', 'tracemalloc=3'],
584+
['-X', 'warn_default_encoding'],
578585
):
579586
with self.subTest(opts=opts):
580587
self.check_options(opts, 'args_from_interpreter_flags')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
All :option:`-X` options from the Python command line are now propagated to
2+
child processes spawned by :mod:`multiprocessing`, not just a hard-coded
3+
subset. This makes the behavior consistent between default "spawn" and
4+
"forkserver" start methods and the old "fork" start method. The options
5+
that were previously not propagated are: ``context_aware_warnings``,
6+
``cpu_count``, ``disable-remote-debug``, ``int_max_str_digits``,
7+
``lazy_imports``, ``no_debug_ranges``, ``pathconfig_warnings``, ``perf``,
8+
``perf_jit``, ``presite``, ``pycache_prefix``, ``thread_inherit_context``,
9+
and ``warn_default_encoding``.

0 commit comments

Comments
 (0)