-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-118234: Document Python subprocess requirement on SystemRoot
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jhohm
wants to merge
7
commits into
python:main
Choose a base branch
from
jhohm:gh-118234-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
167aeba
Further document Python subprocess requirement on `SystemRoot` env, a…
jhohm b4dfc9c
doc: change will to may (so we don't need to communicate patch versio…
gpshead b3285ea
add ! to SystemRoot envvar ref to not link (?)
gpshead 80afcbc
Merge branch 'main' into gh-118234-2
jhohm 0cbf8bc
Avoid warning if any capitalization of SystemRoot in env has a nonemp…
jhohm 9c0ce13
Fix tests to avoid and/or tolerate RuntimeWarning for missing SystemR…
jhohm 62e8465
Revert unneeded change to `test_launcher.RunPyEnv.fake_venv` context.
jhohm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Windows/2025-05-21-10-48-38.gh-issue-118234.x1N6xT.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike this RuntimeWarning. It's ok to run programs without
SystemRoot
env var, or even in an empty environment. It just works fine currently for some programs. Example:This program just works, it displays "Hello World" as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we have 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it works since Windows decided that using
PATH
to locate runtime dependencies (like anLD_LIBRARY_PATH
equivalent) was such a terrible idea that it bypasses it for most OS stuff, but that "fix" upsets people as well.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.
TEMP
), and this change doesn't check for those. But I don't think we have any good way to only warn when things break.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 comment
The 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 comment
The 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 comment
The 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.