Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-118234: Document Python subprocess requirement onSystemRoot
env, add RuntimeWarning#134435
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from6 commits
167aeba
b4dfc9c
b3285ea
80afcbc
0cbf8bc
9c0ce13
62e8465
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1545,6 +1545,10 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, | ||
if cwd is not None: | ||
cwd = os.fsdecode(cwd) | ||
if env is not None and not any( | ||
k.upper() == 'SYSTEMROOT' and v for k, v in env.items()): | ||
warnings.warn("env lacks a valid 'SystemRoot'.", RuntimeWarning) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I dislike this RuntimeWarning. It's ok to run programs without importsubprocess,syscmd= [sys.executable,'-c','print("Hello World")']subprocess.run(cmd,env={}) This program just works, it displays "Hello World" as expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not sure how to synthesize this feedback with#134363 (comment). How do we prevent the problem, if not warning about it, and not setting it in the subprocess? Should we implicitly override the caller's choices and clone SystemRoot into the subprocess env? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't think that wehave to prevent the problem. We can document it and explain how to avoid it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Well, it works since Windows decided that using I'm not particularly strong either way on this fix. It bites people all the time, and it's practically always a pointless thing to do (pass an insufficient environment). At the same time, there are 5-6 other variables that also ought to be included or things will break weirdly (e.g. Is there a silent-by-default-enabled-with-X-dev warning that could be used instead? Would that be okay,@vstinner? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. If we add a warning, it may be better to emit the warning in the socket module, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
A warning only emitted in the Python Developer Mode (-X dev) sounds more acceptable to me, yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
The user's system could be configured to avoid that error, even without the environment variable, while plenty of other parts could also break if they are reconfigured. Launching an application with an empty environment is the bad idea, so that's where the warning should be. I've diagnosed that as the root cause of a lot of issues. Do we have an existing warning? Or do we need to invent a new one? This isn't a deprecation, and that's the only warning I'm aware of. | ||
sys.audit("subprocess.Popen", executable, args, cwd, env) | ||
# Start the process | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -287,7 +287,10 @@ def fake_venv(self): | ||
venv_exe = (venv / ("python_d.exe" if DEBUG_BUILD else "python.exe")) | ||
venv_exe.touch() | ||
try: | ||
yield venv_exe, { | ||
"SystemRoot": os.environ.get("SystemRoot"), | ||
"VIRTUAL_ENV": str(venv.parent), | ||
} | ||
jhohm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
finally: | ||
shutil.rmtree(venv) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Document that :envvar:`!SystemRoot` is also required for a Python subprocess | ||
that uses :mod:`socket` or :mod:`asyncio` on Windows, and add a | ||
:exc:`RuntimeWarning` if an *env* supplied to :class:`subprocess.Popen` | ||
lacks it. Patch by John Keith Hohm. |
Uh oh!
There was an error while loading.Please reload this page.