-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows #14051
bpo-37267: Do not check for FILE_TYPE_CHAR in os.dup() on Windows #14051
Conversation
On Windows, os.dup() no longer creates an inheritable fd when handling a character file.
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.
LGTM.
I tried to understand why _Py_dup() didn't make FILE_TYPE_CHAR non-inheritable. I found my own commit:
... but I don't recall why I had to use:
Maybe it was a limitation in older Windows versions? |
Hum, I found someone reporting ERROR_ACCESS_DENIED error when SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0) is called on a virtual NIC device: Maybe we should try to make the handle non-inheritable but ignore ERROR_ACCESS_DENIED if SetHandleInformation() fails? (and raise for other error codes) |
Maybe it's related to assuming the standard handles have to be inheritable in Windows, and in particular console handles. But the console isn't the only character device in Windows. NUL and COM ports are also character devices. The standard handles don't have to be inheritable. For one example. if the child is a console application, we can rely on the system to duplicate our standard handles to the child under the following conditions:
That said, if This behavior is linked to file descriptors 0-2 as well, since the C runtime couples fds 0-2 with the process standard handles in console applications. For example duping to fd 0 updates the
In this case, a child Python process exits immediately instead of running the REPL because it's executed with an invalid
The result is similar in Linux. On the other hand, Windows diverges from Linux in this case if
|
I'd only ignore the error if |
Thanks @ZackerySpytz for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8. |
GH-14140 is a backport of this pull request to the 3.8 branch. |
GH-14141 is a backport of this pull request to the 3.7 branch. |
…thonGH-14051) On Windows, os.dup() no longer creates an inheritable fd when handling a character file. (cherry picked from commit 28fca0c) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
…thonGH-14051) On Windows, os.dup() no longer creates an inheritable fd when handling a character file.
…thonGH-14051) On Windows, os.dup() no longer creates an inheritable fd when handling a character file.
On Windows, os.dup() no longer creates an inheritable fd when handling a
character file.
https://bugs.python.org/issue37267