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
os: support blocking functions on Windows #101881
Comments
|
When WinAPI When WinAPI Footnotes
|
|
Usage in the io module and test cases will have to be examined for assumptions that partial writes are supported up to the available space in the pipe. On Windows, it's all or nothing in non-blocking mode. If the pipe has 1024 bytes available, then trying to write 2048 bytes will write nothing at all and fail. |
|
Here's an idea to get around the annoying behavior in non-blocking mode. Modify For example, append the following code to the first // A write that exceeds the available size of a pipe never succeeds in
// non-blocking mode. Limiting writes to the pipe size in this case allows
// a buffered write to succeed eventually, as the pipe is read.
DWORD mode, pipe_size;
HANDLE hfile = _Py_get_osfhandle(fd);
if (hfile == INVALID_HANDLE_VALUE) {
return -1;
}
if (gil_held) {
Py_BEGIN_ALLOW_THREADS
if (GetFileType(hfile) == FILE_TYPE_PIPE &&
GetNamedPipeHandleStateW(hfile, &mode,
NULL, NULL, NULL, NULL, 0) &&
mode & PIPE_NOWAIT)
{
// GetNamedPipeInfo() requires FILE_READ_ATTRIBUTES access.
// CreatePipe() includes this access for the write handle.
if (!GetNamedPipeInfo(hfile, NULL, NULL, &pipe_size, NULL)) {
pipe_size = 4096;
}
if (count > pipe_size) {
count = pipe_size;
}
}
Py_END_ALLOW_THREADS
}
else {
if (GetFileType(hfile) == FILE_TYPE_PIPE &&
GetNamedPipeHandleStateW(hfile, &mode,
NULL, NULL, NULL, NULL, 0) &&
mode & PIPE_NOWAIT)
{
if (!GetNamedPipeInfo(hfile, NULL, NULL, &pipe_size, NULL)) {
pipe_size = 4096;
}
if (count > pipe_size) {
count = pipe_size;
}
}
} |
|
The documentation in "Doc/library/os.rst" needs to be updated to indicate the new Windows support in 3.12, i.e. For example: |
Use the GetNamedPipeHandleState and SetNamedPipeHandleState Win32 API functions to add support for os.get_blocking and os.set_blocking.
|
done, anything else needed? |
Use the GetNamedPipeHandleState and SetNamedPipeHandleState Win32 API functions to add support for os.get_blocking and os.set_blocking.
Use the GetNamedPipeHandleState and SetNamedPipeHandleState Win32 API functions to add support for os.get_blocking and os.set_blocking.
…es (GH-101882) * fileutils: handle non-blocking pipe IO on Windows Handle erroring operations on non-blocking pipes by reading the _doserrno code. Limit writes on non-blocking pipes that are too large. * Support blocking functions on Windows Use the GetNamedPipeHandleState and SetNamedPipeHandleState Win32 API functions to add support for os.get_blocking and os.set_blocking.


The os.get_blocking and os.set_blocking functions are only currently supported on Unix.
Linked PRs
The text was updated successfully, but these errors were encountered: