mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
(merge 3.2) Close #12383: Fix subprocess module with env={}: don't copy the
environment variables, start with an empty environment.
This commit is contained in:
commit
372b838db5
3 changed files with 20 additions and 8 deletions
|
@ -1250,7 +1250,7 @@ class Popen(object):
|
||||||
# potential deadlocks, thus we do all this here.
|
# potential deadlocks, thus we do all this here.
|
||||||
# and pass it to fork_exec()
|
# and pass it to fork_exec()
|
||||||
|
|
||||||
if env:
|
if env is not None:
|
||||||
env_list = [os.fsencode(k) + b'=' + os.fsencode(v)
|
env_list = [os.fsencode(k) + b'=' + os.fsencode(v)
|
||||||
for k, v in env.items()]
|
for k, v in env.items()]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -382,13 +382,22 @@ class ProcessTestCase(BaseTestCase):
|
||||||
def test_env(self):
|
def test_env(self):
|
||||||
newenv = os.environ.copy()
|
newenv = os.environ.copy()
|
||||||
newenv["FRUIT"] = "orange"
|
newenv["FRUIT"] = "orange"
|
||||||
p = subprocess.Popen([sys.executable, "-c",
|
with subprocess.Popen([sys.executable, "-c",
|
||||||
'import sys,os;'
|
'import sys,os;'
|
||||||
'sys.stdout.write(os.getenv("FRUIT"))'],
|
'sys.stdout.write(os.getenv("FRUIT"))'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
env=newenv)
|
env=newenv) as p:
|
||||||
self.addCleanup(p.stdout.close)
|
stdout, stderr = p.communicate()
|
||||||
self.assertEqual(p.stdout.read(), b"orange")
|
self.assertEqual(stdout, b"orange")
|
||||||
|
|
||||||
|
def test_empty_env(self):
|
||||||
|
with subprocess.Popen([sys.executable, "-c",
|
||||||
|
'import os; '
|
||||||
|
'print(len(os.environ))'],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
env={}) as p:
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
self.assertEqual(stdout.strip(), b"0")
|
||||||
|
|
||||||
def test_communicate_stdin(self):
|
def test_communicate_stdin(self):
|
||||||
p = subprocess.Popen([sys.executable, "-c",
|
p = subprocess.Popen([sys.executable, "-c",
|
||||||
|
|
|
@ -196,6 +196,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12383: Fix subprocess module with env={}: don't copy the environment
|
||||||
|
variables, start with an empty environment.
|
||||||
|
|
||||||
- Issue #11637: Fix support for importing packaging setup hooks from the
|
- Issue #11637: Fix support for importing packaging setup hooks from the
|
||||||
project directory.
|
project directory.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue