-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-42127 Expand explanation of child process console opening in subprocess doc #97614
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Prev
Previous commit
Merge branch 'main' into gh_42127
- Loading branch information
commit 819ce88c2ae12a5feda659d873ff273295d3eb1c
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
You are viewing a condensed version of this merge commit. You can view the full changes here.
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.
This wording seems to be Windows specific. There is no such thing as a "console" or "console application" or "window manager" or "graphical shell" having anything to do with file descriptors on POSIX systems.
But I think all this needs is some disambiguation wording:
Turn the ; into a . and start a new Windows specific paragraph:
"On Windows, the child's file handles will be inherited from the parent if the child can connect to the console. Otherwise ..."
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 description for Windows needs to be corrected and fleshed out.
If the value is
None, then no redirection occurs. On POSIX, the child inherits a standard file that is not redirected only if its file descriptor (i.e. 0, 1, or 2) is inheritable. The latter is irrespective of the value of theclose_fdsparameter.On Windows, if one or more of the standard files is redirected, then, for each valid standard file that is not redirected, the child inherits a duplicate of the current handle. If the current handle value is
None, a handle for a new pipe is substituted. If none of the standard files is redirected andclose_fdsis false, then the child inherits each standard handle only if it is inheritable. If none of the standard files is redirected, andclose_fdsis true, thestartupinfohandle list is not used explicitly, and the child is a console application that inherits the current console session, then Windows implicitly duplicates the standard handles to the child. Otherwise, the initial standard handle values in the child will be default values. If the child is a console application that is spawned with a new console session, the default standard handles reference console I/O. Else the default values areNone.Beyond just documenting the current behavior in regard to redirecting the standard files, what I'd like to see is new behavior that's more consistent between POSIX and Windows, and behavior that's easier to explain and understand on Windows.
To better match POSIX, the Windows implementation could directly use the current value of a standard handle when it isn't redirected, instead of duplicating an inheritable handle. The pipe fallback for when the current value is
Noneis completely unnecessary behavior. For example, for stdin:If the handle list is used in
_exec_child(), then 0 andNonevalues would have to be filtered out viahandle_list[:] = [int(h) for h in handle_list if h].There's also a behavior difference if none of the standard files is redirected when
close_fdsis true. It could be implemented to always inherit each standard file if the handle is inheritable, as is implemented on POSIX. This entails removing the check in_get_handles()for when none of the standard files is redirected. Instead, when none of the standard files is redirected, it should return the current values inp2cread,c2pwrite, anderrwrite. With this change,Popen()would always useSTARTF_USESTDHANDLES.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.
Instead of all this, I would have added a separate new paragraph, after the text "into the same file handle as for stdout" in the original, which explicitly noted that it was Windows specific. Something like:
This is deliberately a little vague, and only approximates the truth. That's because the actual underlying behaviour is subtle, but it's (IMO) not the job of the Python documentation to explain the nuances of Windows (and the whole console vs GUI application thing).
Honestly, though, I'm not sure this warrants a change in any case. The original issue seems to be arguing for completeness and precision, but doesn't offer any motivating real-world situation where knowing this level of detail is important. I suspect that's either because there isn't one, or there is, but anyone who encounters it has access to far better (more detailed and complete) sources of information1 than we can offer here.
Footnotes
Such as MSDN. ↩