summaryrefslogtreecommitdiff
path: root/Python/fileutils.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-09-09 06:40:42 -0700
committerGitHub <noreply@github.com>2021-09-09 06:40:42 -0700
commit5c65834d801d6b4313eef0684a30e12c22ccfedd (patch)
tree9a071ed023edbe6347013657cd7b990849dcc654 /Python/fileutils.c
parentdc2e11ed5a5a8083db1d8b5e2396c9238999568c (diff)
downloadcpython-git-5c65834d801d6b4313eef0684a30e12c22ccfedd.tar.gz
bpo-44219: Release the GIL during isatty syscalls (GH-28250)
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 06148b1870fceb1a21738761b8e1ac3bf654319b) Co-authored-by: Vincent Michel <vxgmichel@gmail.com>
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 11c659d5a4..d072363535 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -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;
@@ -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) {