mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
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.
This commit is contained in:
parent
ba57963a95
commit
9de3632715
3 changed files with 20 additions and 4 deletions
|
@ -262,9 +262,7 @@ def _args_from_interpreter_flags():
|
||||||
# 'inspect': 'i',
|
# 'inspect': 'i',
|
||||||
# 'interactive': 'i',
|
# 'interactive': 'i',
|
||||||
'dont_write_bytecode': 'B',
|
'dont_write_bytecode': 'B',
|
||||||
'no_user_site': 's',
|
|
||||||
'no_site': 'S',
|
'no_site': 'S',
|
||||||
'ignore_environment': 'E',
|
|
||||||
'verbose': 'v',
|
'verbose': 'v',
|
||||||
'bytes_warning': 'b',
|
'bytes_warning': 'b',
|
||||||
'quiet': 'q',
|
'quiet': 'q',
|
||||||
|
@ -276,6 +274,14 @@ def _args_from_interpreter_flags():
|
||||||
if v > 0:
|
if v > 0:
|
||||||
args.append('-' + opt * v)
|
args.append('-' + opt * v)
|
||||||
|
|
||||||
|
if sys.flags.isolated:
|
||||||
|
args.append('-I')
|
||||||
|
else:
|
||||||
|
if sys.flags.ignore_environment:
|
||||||
|
args.append('-E')
|
||||||
|
if sys.flags.no_user_site:
|
||||||
|
args.append('-s')
|
||||||
|
|
||||||
# -W options
|
# -W options
|
||||||
warnopts = sys.warnoptions[:]
|
warnopts = sys.warnoptions[:]
|
||||||
bytes_warning = sys.flags.bytes_warning
|
bytes_warning = sys.flags.bytes_warning
|
||||||
|
|
|
@ -456,7 +456,7 @@ class TestSupport(unittest.TestCase):
|
||||||
# pending child process
|
# pending child process
|
||||||
support.reap_children()
|
support.reap_children()
|
||||||
|
|
||||||
def check_options(self, args, func):
|
def check_options(self, args, func, expected=None):
|
||||||
code = f'from test.support import {func}; print(repr({func}()))'
|
code = f'from test.support import {func}; print(repr({func}()))'
|
||||||
cmd = [sys.executable, *args, '-c', code]
|
cmd = [sys.executable, *args, '-c', code]
|
||||||
env = {key: value for key, value in os.environ.items()
|
env = {key: value for key, value in os.environ.items()
|
||||||
|
@ -466,7 +466,9 @@ class TestSupport(unittest.TestCase):
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
universal_newlines=True,
|
universal_newlines=True,
|
||||||
env=env)
|
env=env)
|
||||||
self.assertEqual(proc.stdout.rstrip(), repr(args))
|
if expected is None:
|
||||||
|
expected = args
|
||||||
|
self.assertEqual(proc.stdout.rstrip(), repr(expected))
|
||||||
self.assertEqual(proc.returncode, 0)
|
self.assertEqual(proc.returncode, 0)
|
||||||
|
|
||||||
def test_args_from_interpreter_flags(self):
|
def test_args_from_interpreter_flags(self):
|
||||||
|
@ -482,6 +484,7 @@ class TestSupport(unittest.TestCase):
|
||||||
['-v'],
|
['-v'],
|
||||||
['-b'],
|
['-b'],
|
||||||
['-q'],
|
['-q'],
|
||||||
|
['-I'],
|
||||||
# same option multiple times
|
# same option multiple times
|
||||||
['-bb'],
|
['-bb'],
|
||||||
['-vvv'],
|
['-vvv'],
|
||||||
|
@ -500,6 +503,9 @@ class TestSupport(unittest.TestCase):
|
||||||
with self.subTest(opts=opts):
|
with self.subTest(opts=opts):
|
||||||
self.check_options(opts, 'args_from_interpreter_flags')
|
self.check_options(opts, 'args_from_interpreter_flags')
|
||||||
|
|
||||||
|
self.check_options(['-I', '-E', '-s'], 'args_from_interpreter_flags',
|
||||||
|
['-I'])
|
||||||
|
|
||||||
def test_optim_args_from_interpreter_flags(self):
|
def test_optim_args_from_interpreter_flags(self):
|
||||||
# Test test.support.optim_args_from_interpreter_flags()
|
# Test test.support.optim_args_from_interpreter_flags()
|
||||||
for opts in (
|
for opts in (
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
The :option:`-I` command line option (run Python in isolated mode) is now
|
||||||
|
also copied by the :mod:`multiprocessing` and :mod:`distutils` modules when
|
||||||
|
spawning child processes. Previously, only :option:`-E` and :option:`-s` options
|
||||||
|
(enabled by :option:`-I`) were copied.
|
Loading…
Add table
Add a link
Reference in a new issue