GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-118234: Document Python subprocess requirement on `SystemRoot` env, add RuntimeWarning by jhohm · Pull Request #134435 · python/cpython

Conversation

@jhohm

@jhohm jhohm commented May 21, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Document thatSystemRoot is also required for a Python subprocess that uses socket or asyncio on Windows, and add a RuntimeWarning if an env supplied to subprocess.Popen lacks it.

Resolves #118234.

  • Issue: sockets and asyncio on Windows depend on SYSTEMROOT env var #118234

📚 Documentation preview 📚: https://cpython-previews--134435.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jhohm
Further document Python subprocess requirement on SystemRoot env, a…
167aeba
…dd RuntimeWarning
@jhohm
jhohm requested a review from gpshead as a code owner May 21, 2025 15:18
@bedevere-app bedevere-app Bot mentioned this pull request May 21, 2025
sockets and asyncio on Windows depend on SYSTEMROOT env var #118234
Open
@bedevere-app bedevere-app Bot added the awaiting review label May 21, 2025
gpshead added 2 commits May 21, 2025 11:34
@gpshead
doc: change will to may (so we don't need to communicate patch versio…
b4dfc9c
…n details).
@gpshead
add ! to SystemRoot envvar ref to not link (?)
b3285ea
@gpshead gpshead self-assigned this May 21, 2025
@gpshead gpshead added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels May 21, 2025
@jhohm jhohm mentioned this pull request May 21, 2025
gh-118234: Avoid socket failure with missing SYSTEMROOT env var on Windows #134363
Closed
@jhohm
Merge branch 'main' into pythongh-118234-2
80afcbc
vstinner
vstinner reviewed May 21, 2025
View reviewed changes
Comment thread Lib/subprocess.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jhohm
Avoid warning if any capitalization of SystemRoot in env has a nonemp…
0cbf8bc
…ty value.
@jhohm

jhohm commented May 21, 2025

Copy link
Copy Markdown
Contributor Author

Apparently some regression tests trigger this: https://github.com/python/cpython/actions/runs/15171090613/job/42661034135

Even though test.libregrtest.worker.create_worker_process initilaizes env = dict(os.environ).

Does the Windows CI runner not set SystemRoot?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 21, 2025

Copy link
Copy Markdown
Member

Does the Windows CI runner not set SystemRoot?

You can check "Display build info" which says:

os.environ[SYSTEMROOT]: C:\Windows
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jhohm
Fix tests to avoid and/or tolerate RuntimeWarning for missing SystemR…
9c0ce13
…oot.
zooba
zooba reviewed May 21, 2025
View reviewed changes
Comment thread Lib/test/test_launcher.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@zooba

zooba commented May 21, 2025

Copy link
Copy Markdown
Member

Does the Windows CI runner not set SystemRoot?

I'd be suspicious of Lib\test\libregrtest\save_env.py and get_os_environ and restore_os_environ. A bit of logging in those might show a place where it's not resetting things properly (even if it resets them properly later).

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gpshead gpshead assigned zooba and unassigned gpshead May 22, 2025
@jhohm
Revert unneeded change to test_launcher.RunPyEnv.fake_venv context.
62e8465
vstinner
vstinner reviewed May 22, 2025
View reviewed changes
Comment thread Lib/subprocess.py

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)

@vstinner vstinner May 22, 2025

Copy link
Copy Markdown
Member

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:

import subprocess, sys
cmd = [sys.executable, '-c', 'print("Hello World")']
subprocess.run(cmd, env={})

This program just works, it displays "Hello World" as expected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jhohm jhohm May 22, 2025

Copy link
Copy Markdown
Contributor Author

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 22, 2025

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba May 22, 2025

Copy link
Copy Markdown
Member

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 an LD_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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 22, 2025

Copy link
Copy Markdown
Member

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 22, 2025

Copy link
Copy Markdown
Member

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.

Is there a silent-by-default-enabled-with-X-dev warning that could be used instead? Would that be okay, @vstinner?

A warning only emitted in the Python Developer Mode (-X dev) sounds more acceptable to me, yes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba May 23, 2025

Copy link
Copy Markdown
Member

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.

it may be better to emit the warning in the socket module, no?

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Apr 25, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 25, 2026
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.15 bugs and security fixes label May 30, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label May 31, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Aug 5, 2026
Task 24: add local Showdown oracle chrismaghuhn/BattleBelief#35
Merged
@coderabbitai coderabbitai Bot mentioned this pull request Aug 13, 2026
feat(events): relocate the hook event channel to a user-scoped state root (#494) bmad-code-org/bmad-loop#568
Merged
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments
@zooba zooba zooba left review comments
@gpshead gpshead Awaiting requested review from gpshead gpshead is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@zooba zooba

Labels

awaiting review needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

sockets and asyncio on Windows depend on SYSTEMROOT env var

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@jhohm @vstinner @zooba @gpshead @serhiy-storchaka
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.