[issue45944] Avoid calling isatty() for most open() calls

Eryk Sun report at bugs.python.org
Wed Dec 1 06:53:13 EST 2021


Eryk Sun <eryksun at gmail.com> added the comment:

> make it returning False without invoking a system call if the file
> size is non-zero it will eliminate the need to expose _size.

I suggest using the file type instead of the size. There's no reason to call isatty() if it's not an S_IFCHR file. This will avoid calling isatty() on regular files that happen to be empty.

In Windows, isatty(fd) is based solely on the file type, which is flagged in the fd record when a file descriptor is opened for a native file handle. It's not a system call, but it's also nearly worthless for how isatty() is typically used, since it's true for any S_IFCHR file (e.g. con, nul, com1).

----------
nosy: +eryksun

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45944>
_______________________________________


More information about the Python-bugs-list mailing list