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
Closed
Feat: Fix Windows handle invalid error with subprocess.Popen under capture (Python 3.14)#14348harsh21234i wants to merge 6 commits intopytest-dev:mainfrom
harsh21234i wants to merge 6 commits intopytest-dev:mainfrom
Conversation
…n subprocess under capture (Python 3.14)
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Member
|
As far as i can tell this was missconfigured lazy ai based contribution |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.