10000 bpo-34812: subprocess._args_from_interpreter_flags(): add isolated (G… · python/cpython@9de3632 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9de3632

Browse files
authored
bpo-34812: subprocess._args_from_interpreter_flags(): add isolated (GH-10675)
The "-I" command line option (run Python in isolated mode) is now also copied by the multiprocessing and distutils modules when spawning child processes. Previously, only -E and -s options (enabled by -I) were copied. subprocess._args_from_interpreter_flags() now copies the -I flag.
1 parent ba57963 commit 9de3632

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Lib/subprocess.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ def _args_from_interpreter_flags():
262262
# 'inspect': 'i',
263263
# 'interactive': 'i',
264264
'dont_write_bytecode': 'B',
265-
'no_user_site': 's',
266265
'no_site': 'S',
267-
'ignore_environment': 'E',
268266
'verbose': 'v',
269267
'bytes_warning': 'b',
270268
'quiet': 'q',
@@ -276,6 +274,14 @@ def _args_from_interpreter_flags():
276274
if v > 0:
277275
args.append('-' + opt * v)
278276

277+
if sys.flags.isolated:
278+
args.append('-I')
279+
else:
280+
if sys.flags.ignore_environment:
281+
args.append('-E')
282+
if sys.flags.no_user_site:
283+
args.append('-s')
284+
279285
# -W options
280286
warnopts = sys.warnoptions[:]
281287
bytes_warning = sys.flags.bytes_warning

Lib/test/test_support.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def test_reap_children(self):
456456
# pending child process
457457
support.reap_children()
458458

459-
def check_options(self, args, func):
459+
def check_options(self, args, func, expected=None):
460460
code = f'from test.support import {func}; print(repr({func}()))'
461461
cmd = [sys.executable, *args, '-c', code]
462462
env = {key: value for key, value in os.environ.items()
@@ -466,7 +466,9 @@ def check_options(self, args, func):
466466
stderr=subprocess.DEVNULL,
467467
universal_newlines=True,
468468
env=env)
469-
self.assertEqual(proc.stdout.rstrip(), repr(args))
469+
if expected is None:
470+
expected = args
471+
self.assertEqual(proc.stdout.rstrip(), repr(expected))
470472
self.assertEqual(proc.returncode, 0)
471473

472474
def test_args_from_interpreter_flags(self):
@@ -482,6 +484,7 @@ def test_args_from_interpreter_flags(self):
482484
['-v'],
483485
['-b'],
484486
['-q'],
487+
['-I'],
485488
# same option multiple times
486489
['-bb'],
487490
['-vvv'],
@@ -500,6 +503,9 @@ def test_args_from_interpreter_flags(self):
500503
with self.subTest(opts=opts):
501504
self.check_options(opts, 'args_from_interpreter_flags')
502505

506+
self.check_options(['-I', '-E', '-s'], 'args_from_interpreter_flags',
507+
['-I'])
508+
503509
def test_optim_args_from_interpreter_flags(self):
504510
# Test test.support.optim_args_from_interpreter_flags()
505511
for opts in (
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The :option:`-I` command line option (run Python in isolated mode) is now
2+
also copied by the :mod:`multiprocessing` and :mod:`distutils` modules when
3+
spawning child processes. Previously, only :option:`-E` and :option:`-s` options
4+
(enabled by :option:`-I`) were copied.

0 commit comments

Comments
 (0)
0