Skip to content

gh-145311: fix ensurepip and venv hang when stdin is a pipe#146010

Closed
lex00 wants to merge 2 commits intopython:mainfrom
lex00:gh-145311-ensurepip-hang
Closed

gh-145311: fix ensurepip and venv hang when stdin is a pipe#146010
lex00 wants to merge 2 commits intopython:mainfrom
lex00:gh-145311-ensurepip-hang

Conversation

@lex00
Copy link

@lex00 lex00 commented Mar 16, 2026

When a process spawns Python with an open pipe on stdin and never writes to it, ensurepip._run_pip() and venv.EnvBuilder._call_new_python() can hang indefinitely because the subprocess inherits the pipe and blocks waiting for input.

Fix: pass stdin=subprocess.DEVNULL to both calls.

Regression tests added for both code paths: a mock-based test that checks the kwarg is set, and an integration test that reproduces the hang condition with a real subprocess.

#145311

Pass `stdin=subprocess.DEVNULL` to the subprocess calls in
`ensurepip._run_pip()` and `venv.EnvBuilder._call_new_python()` so they
do not inherit an open pipe from the parent process and hang waiting for
input that never arrives.
@python-cla-bot
Copy link

python-cla-bot bot commented Mar 16, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@picnixz
Copy link
Member

picnixz commented Mar 16, 2026

There is no consensus on whether the issue is accepted. Please avoid opening PRs for issues that are not yet triaged. Thanks.

@picnixz picnixz closed this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants