diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 73e7e60fe6..f844e07cf2 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -10067,7 +10067,9 @@ os_isatty_impl(PyObject *module, int fd) { int return_value; _Py_BEGIN_SUPPRESS_IPH + Py_BEGIN_ALLOW_THREADS return_value = isatty(fd); + Py_END_ALLOW_THREADS _Py_END_SUPPRESS_IPH return return_value; } diff --git a/Python/fileutils.c b/Python/fileutils.c index e8a7eda505..bf8da0599d 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -68,7 +68,9 @@ _Py_device_encoding(int fd) { int valid; _Py_BEGIN_SUPPRESS_IPH + Py_BEGIN_ALLOW_THREADS valid = isatty(fd); + Py_END_ALLOW_THREADS _Py_END_SUPPRESS_IPH if (!valid) Py_RETURN_NONE; @@ -1776,12 +1778,22 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held) _Py_BEGIN_SUPPRESS_IPH #ifdef MS_WINDOWS - if (count > 32767 && isatty(fd)) { + if (count > 32767) { /* Issue #11395: the Windows console returns an error (12: not enough space error) on writing into stdout if stdout mode is binary and the length is greater than 66,000 bytes (or less, depending on heap usage). */ - count = 32767; + if (gil_held) { + Py_BEGIN_ALLOW_THREADS + if (isatty(fd)) { + count = 32767; + } + Py_END_ALLOW_THREADS + } else { + if (isatty(fd)) { + count = 32767; + } + } } #endif if (count > _PY_WRITE_MAX) {