gh-101881: Support (non-)blocking read/write functions on Windows pip… · python/cpython@739c026 · GitHub
Skip to content

Commit 739c026

Browse files
authored
gh-101881: Support (non-)blocking read/write functions on Windows pipes (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.
1 parent 36b139a commit 739c026

8 files changed

Lines changed: 107 additions & 25 deletions

File tree

Doc/library/os.rst

Lines changed: 10 additions & 2 deletions

Include/internal/pycore_fileutils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ PyAPI_FUNC(int) _Py_set_inheritable_async_safe(int fd, int inheritable,
160160

161161
PyAPI_FUNC(int) _Py_dup(int fd);
162162

163-
#ifndef MS_WINDOWS
164163
PyAPI_FUNC(int) _Py_get_blocking(int fd);
165164

166165
PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking);
167-
#else /* MS_WINDOWS */
166+
167+
#ifdef MS_WINDOWS
168168
PyAPI_FUNC(void*) _Py_get_osfhandle_noraise(int fd);
169169

170170
PyAPI_FUNC(void*) _Py_get_osfhandle(int fd);

Lib/test/test_os.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,7 @@ def test_path_t_converter_and_custom_class(self):
40994099
@unittest.skipUnless(hasattr(os, 'get_blocking'),
41004100
'needs os.get_blocking() and os.set_blocking()')
41014101
@unittest.skipIf(support.is_emscripten, "Cannot unset blocking flag")
4102+
@unittest.skipIf(sys.platform == 'win32', 'Windows only supports blocking on pipes')
41024103
class BlockingTests(unittest.TestCase):
41034104
def test_blocking(self):
41044105
fd = os.open(__file__, os.O_RDONLY)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for the os.get_blocking() and os.set_blocking() functions on Windows.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle read and write operations on non-blocking pipes properly on Windows.

Modules/clinic/posixmodule.c.h

Lines changed: 1 addition & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/posixmodule.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13930,7 +13930,6 @@ os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
1393013930
}
1393113931
#endif /* MS_WINDOWS */
1393213932

13933-
#ifndef MS_WINDOWS
1393413933
/*[clinic input]
1393513934
os.get_blocking -> bool
1393613935
fd: int
@@ -13978,7 +13977,6 @@ os_set_blocking_impl(PyObject *module, int fd, int blocking)
1397813977
return NULL;
1397913978
Py_RETURN_NONE;
1398013979
}
13981-
#endif /* !MS_WINDOWS */
1398213980

1398313981

1398413982
/*[clinic input]

Python/fileutils.c

Lines changed: 91 additions & 2 deletions

0 commit comments

Comments
 (0)