Skip to content

Feat: Fix Windows handle invalid error with subprocess.Popen under capture (Python 3.14)#14348

Closed
harsh21234i wants to merge 6 commits intopytest-dev:mainfrom
harsh21234i:fix/windows-stdin-handle
Closed

Feat: Fix Windows handle invalid error with subprocess.Popen under capture (Python 3.14)#14348
harsh21234i wants to merge 6 commits intopytest-dev:mainfrom
harsh21234i:fix/windows-stdin-handle

Conversation

@harsh21234i
Copy link
Copy Markdown

Fixes #14323

Fixes a Windows-specific issue on Python 3.14 where subprocess.Popen may raise
[WinError 6] The handle is invalid when pytest capture is active.

Root cause:
After os.dup2() in FDCaptureBase.start(), the C runtime file descriptor table
is updated, but the Windows process-level STD_INPUT_HANDLE remains stale.
subprocess retrieves this stale handle via GetStdHandle, causing
DuplicateHandle to fail.

Fix:
After dup2, explicitly synchronize the Windows STD_INPUT_HANDLE using
SetStdHandle to match the new fd 0 handle.

This keeps both handle systems consistent and avoids invalid handle usage.

@RonnyPfannschmidt
Copy link
Copy Markdown
Member

RonnyPfannschmidt commented Apr 5, 2026

As far as i can tell this was missconfigured lazy ai based contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] subprocess.Popen with DEVNULL raises [WinError 6] when pytest captures stdin

2 participants