[New-bugs-announce] [issue34070] Superfluous call to isatty in open() when buffering >= 0
David Herberth
report at bugs.python.org
Sun Jul 8 14:12:53 EDT 2018
New submission from David Herberth <python at dav1d.de>:
_iomodule.c:_io_open_impl checks for isatty even if not necessary (when buffering >= 0).
Code: https://github.com/python/cpython/blob/c0ee341b29bd7d978b49272a2c0e2dcfa77404d5/Modules/_io/_iomodule.c#L392
{
PyObject *res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
if (res == NULL)
goto error;
isatty = PyLong_AsLong(res);
Py_DECREF(res);
if (isatty == -1 && PyErr_Occurred())
goto error;
}
if (buffering == 1 || (buffering < 0 && isatty)) {
buffering = -1;
line_buffering = 1;
}
else
line_buffering = 0;
Python Code to reproduce:
with open('foo', 'rb', buffering=0) as f:
f.read()
This generates an error (can be seen with strace):
ioctl(5, TCGETS, 0x7ffef1435b60) = -1 ENOTTY (Inappropriate ioctl for device)
I'll open a PR shortly.
----------
components: IO
messages: 321281
nosy: Dav1d
priority: normal
severity: normal
status: open
title: Superfluous call to isatty in open() when buffering >= 0
type: performance
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34070>
_______________________________________
More information about the New-bugs-announce
mailing list