-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
doc: subprocess: inheritance of std descriptors inconsistent #42127
Comments
The inheritance of std descriptors is inconsistent If one calls Popen with stdin = stdout = stderr = None, 655 def _get_handles(self, stdin, stdout, I suggest to just remove those lines 659 and 660. The |
This is a correct observation. However, the current implementation is not necessarily wrong. This could instead be seen as a consequence of the different environments. The subprocess documentation states that "With None, no redirection will occur". So, it becomes an interpretation of what this really mean. Since the "default" behaviour on UNIX is to inherit and the default behaviour on Windows is to attach the standard handles to (an often newly created) console window, one could argue that this fits fairly good with the description "no redirection will occur". If we would change this, so that the parents handles are always inherited, then how would you specify that you want to attach the standard handles to the new console window? For best flexibility, the API should allow both cases: Both inherit all handles from the parent as well as attaching all standard handles to the new console window. As you point out, the current API allows this. So why change this? One thing that's clearly an bug is the second part of the documentation: "With None, no redirection will occur; the child's file handles will be inherited from the This is currently only true on UNIX. If we should keep the current behaviour, at least the comment needs to be fixed. |
Note to others searching for a solution to this and similar problems: Thanks! |
I think all that is needed is a documentation patch. Attached is a doc patch which changes the doc to explicitly describe what happens on unix & windows (as described by Peter). |
The patch needs to be converted into a github PR. |
In the default case, In particular, if the executable image of the child is a console application, the system duplicates the parent's standard handles to the child, as well as a handle for the parent's console session, if any. If the child can connect to the parent's console at startup, then the duplicated standard handles are used, whatever they are. (In general, they need to be handles for pipe, character, or disk files opened in synchronous mode, as required by C standard I/O.) If the child can't connect to a console session, it allocates a new console and opens the console "Input" and "Output" as its standard handles. On the other hand, if the executable image of the child is not a console application, the system does not implicitly duplicate standard handles from the parent to the child. The window manager and graphical shell even explicitly reuse the standard-handle values (via |
I have submitted a discussion to the core-mentorship list, with a possible resolution. Since this is my first contribution, trying to get good feedback. |
Due to multiple core-dev conflicting recomendations, and in agreement with @LeamHall's observation:
Closing this issue. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: