-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subprocess.run(..., env={})
broken on Windows
#105436
Comments
The error occurs in the _winapi_CreateProcess_impl function of cpython/Modules/_winapi.c. |
Yes, Lines 798 to 806 in 7279fb6
|
…_t values (pythonGH-105495) (cherry picked from commit 4f7d3b6) Co-authored-by: Dora203 <[email protected]>
…_t values (pythonGH-105495) (cherry picked from commit 4f7d3b6) Co-authored-by: Dora203 <[email protected]>
Thanks for the report and to @sku2000 for the fix! |
The test fails in situations where processes can't launch without a valid environment (fairly common on Windows). We should replace the test with one that checks that |
If we don't care about the exit status of the chid process, we can modify it like this: @unittest.skipUnless(mswindows, "Maybe test trigger a leak on Ubuntu")
def test_run_with_an_empty_env(self):
# gh-105436: fix subprocess.run(..., env={}) broken on Windows
args = [sys.executable, "-c", 'import sys; sys.exit(57)']
subprocess.run(args, env={}) Don't have to ignore other exceptions. |
I'd prefer for the new test to be placed immediately after the existing case @unittest.skipUnless(mswindows, "relaxed test for Windows")
def test_empty_env_windows(self):
# gh-105436: fix subprocess.run(..., env={}) on Windows
args = [sys.executable, '-X', 'utf8', '-c',
'import os; print(list(os.environ))']
p = subprocess.run(args, env={}, capture_output=True)
# Executing Python may depend on SystemRoot and/or PATH. If the child
# succeeds, which should be the case for 3.12+ on x86/x64, then
# verify that it was started with an empty environment.
if p.returncode == 0:
self.assertEqual(eval(p.stdout), []) |
…honGH-105742) (cherry picked from commit 4cefe3c) Co-authored-by: Steve Dower <[email protected]>
…honGH-105742) (cherry picked from commit 4cefe3c) Co-authored-by: Steve Dower <[email protected]>
Further enhancing the test is fine, I'm just unblocking buildbots for now. |
Bug report
When passing an empty dictionary as
env
tosubprocess.run
(orPopen
), I get the following error:Environment
Linked PRs
The text was updated successfully, but these errors were encountered: