-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-77046: Pass the _O_NOINHERIT flag to _open_osfhandle() calls #13739
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
gh-77046: Pass the _O_NOINHERIT flag to _open_osfhandle() calls #13739
Conversation
On Windows, do not use inheritable file descriptors to wrap handles in os.pipe().
This change should have a unit test, though it is difficult to create one that doesn't cause debug assertion failures in the MSVC runtime library when run. |
Do you mean the dialog box used by the debug CRT for warnings, errors, and failed assertions, such as a failed assertion if an invalid fd is passed to (It also calls |
Thank you for the comment, @eryksun.
Yes.
Why exactly? Such a change is not likely to be accepted by CPython unless there is an actual bug to be fixed. |
Okay, so a unit test can be added to ensure the fd isn't inherited as long as we suppress these warnings. Note that fixing this means that
There's no reason to use ctypes if we already have a builtin module that provides the function. Dependence on ctypes in the unit tests should be minimized if possible. One day we might want to make it optional in Windows as well. For example, say if Windows supports an architecture that libffi doesn't support or doesn't support for the required calling convention. Another issue to be addressed is the Windows implementation of Maybe the behavior of console applications has confused the author of this code. When a console process is created, if its console is inherited and if its startup info doesn't have the flag |
IMO the existing test_os.test_pipe() is enough:
|
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, but I added a minor request. Can you try to rebase your PR?
IMO we should always pass _O_NOINHERIT flag in msvcrt.open_osfhandle(). For example, we do the same in select.epoll(). It can be addressed in a separated issue, or the same PR. It's up to you.
@@ -0,0 +1,2 @@ | |||
On Windows, do not use inheritable file descriptors to wrap handles in | |||
:func:`os.pipe`. |
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.
Would you mind to also document _io._WindowsConsoleIO.fileno() fix?
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.
Thank you, Victor, for looking at this PR -- I will update it soon.
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 has merge conflicts now.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Maybe a better approach would replace _open_osfhandle() with _Py_open_osfhandle_noraise(), and modify _Py_open_osfhandle_noraise() so it always sets the _O_NOINHERIT flag. |
ISTM this was fixed by #1927. |
@erlend-aasland: PR #1927 added |
This change now has merge conflicts and it seems like @ZackerySpytz is no longer active. I wrote a new PR #113817 based on this PR and on the up to date main branch. I close this PR. |
On Windows, do not use inheritable file descriptors to wrap handles
in os.pipe().
#77046