Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release the GIL while performing ``isatty`` system calls on arbitrary file
descriptors. In particular, this affects :func:`os.isatty`,
:func:`os.device_encoding` and :class:`io.TextIOWrapper`. By extension,
:func:`io.open` in text mode is also affected.
2 changes: 2 additions & 0 deletions 2 Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -10058,9 +10058,11 @@ os_isatty_impl(PyObject *module, int fd)
/*[clinic end generated code: output=6a48c8b4e644ca00 input=08ce94aa1eaf7b5e]*/
{
int return_value;
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
return_value = isatty(fd);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
return return_value;
}

Expand Down
16 changes: 14 additions & 2 deletions 16 Python/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ _Py_device_encoding(int fd)
UINT cp;
#endif
int valid;
Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
valid = isatty(fd);
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
if (!valid)
Py_RETURN_NONE;

Expand Down Expand Up @@ -1737,12 +1739,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) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.