8000 gh-121940: Stop checking isatty on Windows write() · cmaloney/cpython@a5c703f · GitHub
[go: up one dir, main page]

Skip to content

Commit a5c703f

Browse files
committed
pythongh-121940: Stop checking isatty on Windows write()
This check was added for bpo-11395 in 2011. Versions of Windows before Windows 8 required the check as write size to a tty was limited ( python#55604 (comment)). Based on PEP 11, the last Windows 8 support ended in 2023, so this is no longer needed on any currently supported windows platforms. That large writes to console succeed is tested by test_os.test_write_windows_console, which passes in my testing on Windows 11. It's possible there are still objects on windows which error on a write too large, this leaves in place some code to handle (ex. Pipes and ENOSPC). Write can also still be interrupted and resumed (EAGAIN, etc). If there are other Windows objects or platform files which limit write size, callers should wrap the `os.write` function.
1 parent 51da3df commit a5c703f

File tree

3 files changed

+4
-32
lines changed

3 files changed

+4
-32
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``os.write`` on Windows no longer limits or splits up writes to console
2+
objects. The behavior was initially added to address bpo-11395 in 2011 as a
3+
workaround for the OS returning an error with too large of a write call to
4+
a console.

Modules/_io/winconsoleio.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,18 +1023,6 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, PyTypeObject *cls,
10231023

10241024
Py_BEGIN_ALLOW_THREADS
10251025
wlen = MultiByteToWideChar(CP_UTF8, 0, b->buf, len, NULL, 0);
1026-
1027-
/* issue11395 there is an unspecified upper bound on how many bytes
1028-
can be written at once. We cap at 32k - the caller will have to
1029-
handle partial writes.
1030-
Since we don't know how many input bytes are being ignored, we
1031-
have to reduce and recalculate. */
1032-
while (wlen > 32766 / sizeof(wchar_t)) {
1033-
len /= 2;
1034-
/* Fix for github issues gh-110913 and gh-82052. */
1035-
len = _find_last_utf8_boundary(b->buf, len);
1036-
wlen = MultiByteToWideChar(CP_UTF8, 0, b->buf, len, NULL, 0);
1037-
}
10381026
Py_END_ALLOW_THREADS
10391027

10401028
if (!wlen)

Python/fileutils.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,26 +1922,6 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
19221922
int async_err = 0;
19231923

19241924
_Py_BEGIN_SUPPRESS_IPH
1925-
#ifdef MS_WINDOWS
1926-
if (count > 32767) {
1927-
/* Issue #11395: the Windows console returns an error (12: not
1928-
enough space error) on writing into stdout if stdout mode is
1929-
binary and the length is greater than 66,000 bytes (or less,
1930-
depending on heap usage). */
1931-
if (gil_held) {
1932-
Py_BEGIN_ALLOW_THREADS
1933-
if (isatty(fd)) {
1934-
count = 32767;
1935-
}
1936-
Py_END_ALLOW_THREADS
1937-
} else {
1938-
if (isatty(fd)) {
1939-
count = 32767;
1940-
}
1941-
}
1942-
}
1943-
1944-
#endif
19451925
if (count > _PY_WRITE_MAX) {
19461926
count = _PY_WRITE_MAX;
19471927
}

0 commit comments

Comments
 (0)
0