mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-30555: Fix WindowsConsoleIO fails in the presence of fd redirection (GH-1927)
This works by not caching the handle and instead getting the handle from the file descriptor each time, so that if the actual handle changes by fd redirection closing/opening the console handle beneath our feet, we will keep working correctly.
This commit is contained in:
parent
6b59e662fa
commit
5e437fb872
10 changed files with 144 additions and 125 deletions
|
|
@ -10098,18 +10098,16 @@ os_pipe_impl(PyObject *module)
|
|||
attr.bInheritHandle = FALSE;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
_Py_BEGIN_SUPPRESS_IPH
|
||||
ok = CreatePipe(&read, &write, &attr, 0);
|
||||
if (ok) {
|
||||
fds[0] = _open_osfhandle((intptr_t)read, _O_RDONLY);
|
||||
fds[1] = _open_osfhandle((intptr_t)write, _O_WRONLY);
|
||||
fds[0] = _Py_open_osfhandle_noraise(read, _O_RDONLY);
|
||||
fds[1] = _Py_open_osfhandle_noraise(write, _O_WRONLY);
|
||||
if (fds[0] == -1 || fds[1] == -1) {
|
||||
CloseHandle(read);
|
||||
CloseHandle(write);
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
_Py_END_SUPPRESS_IPH
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
if (!ok)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue