[New-bugs-announce] [issue44219] Opening a file holds the GIL when it calls "isatty()"

Matthias Urlichs report at bugs.python.org
Sun May 23 13:18:13 EDT 2021

New submission from Matthias Urlichs <matthias at urlichs.de>:

Opening a file calls `isatty` which calls an ioctl with the GIL held.

#0  __GI___tcgetattr (fd=18, termios_p=termios_p at entry=0x7f618a5df920)
    at ../sysdeps/unix/sysv/linux/tcgetattr.c:38
#1  0x00007f618bd1ca0c in __isatty (fd=<optimized out>) at ../sysdeps/posix/isatty.c:27
#2  0x000000000062b746 in _Py_device_encoding (fd=<optimized out>) at ../Python/fileutils.c:62
#3  0x000000000060bf90 in _io_TextIOWrapper___init___impl (write_through=0, line_buffering=0, 
    newline=0x0, errors='strict', encoding=<optimized out>, 
    buffer=<_io.BufferedWriter at remote 0x7f618986aeb0>, self=0x7f618985a860)
    at ../Modules/_io/textio.c:1149

Please don't do that.

In my case, the file in question is implemented as a FUSE mount which is served by the same process (different thread of course). Thus holding the GIL at this point causes a rather interesting deadlock.

Tested with 3.9.

components: Interpreter Core
messages: 394208
nosy: smurfix
priority: normal
severity: normal
status: open
title: Opening a file holds the GIL when it calls "isatty()"
type: crash
versions: Python 3.10, Python 3.11, Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list