mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-44219: Release the GIL during isatty syscalls (GH-28250) (GH-28255)
Release the GIL while performing isatty() system calls on arbitrary
file descriptors. In particular, this affects os.isatty(),
os.device_encoding() and io.TextIOWrapper. By extension,
io.open() in text mode is also affected.
(cherry picked from commit 06148b1870
)
Co-authored-by: Vincent Michel <vxgmichel@gmail.com>
This commit is contained in:
parent
11103eb1f2
commit
23c46778d6
3 changed files with 20 additions and 2 deletions
|
@ -67,9 +67,11 @@ PyObject *
|
|||
_Py_device_encoding(int fd)
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue