[New-bugs-announce] [issue37696] FileIO.read() on a closed TTY throws an exception prematurely

David Wilson report at bugs.python.org
Sun Jul 28 10:51:10 EDT 2019


New submission from David Wilson <dw at botanicus.net>:

Given:

    $ cat tty-failure.py 

    import pty
    import os

    master, slave = pty.openpty()
    master = os.fdopen(master, 'r+b', 0)
    slave = os.fdopen(slave, 'r+b', 0)
    slave.write(b'foo')
    slave.close()
    print(master.read())

On Python 2, read() would return b'foo', with subsequent calls raising IOError, whereas on Python 3 an OSError is raised due to the underlying file descriptor returning EIO.

In the case of a PTY, EIO indicates the remote side has hung up and more or less can be treated as an EOF indicator.

On Python 3 the partial buffer should not be discarded when a subsequent read() syscall returns an error.

Secondarily, the change from IOError to OSError looks wrong. Does anyone know what's going on there? I would never expect to see OSError raised by a builtin

----------
components: IO
messages: 348578
nosy: dw
priority: normal
severity: normal
status: open
title: FileIO.read() on a closed TTY throws an exception prematurely
type: behavior
versions: Python 3.9

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


More information about the New-bugs-announce mailing list