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

2019-08-08 Thread David Wilson
David Wilson added the comment: A real example of where returning the partial buffer is dangerous would be EBADF. - Repeated reading succeeds, building up a partial buffer. Another thread runs, and buggy code causes an unrelated fd blonging to the file object to be closed. - Original thread

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

2019-08-08 Thread David Wilson
David Wilson added the comment: If we treat different errnos specially, the list of 'okay to silently fail' errors seems quite succinct. In another project I treat EIO, EPIPE and ECONNRESET as EOF, and raise all others -- https://github.com/dw/mitogen/blob/c6de090f083a58344e91ab97847bf7ae3fe

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

2019-08-08 Thread David Wilson
David Wilson added the comment: Interesting, this immediately turns into a little rabbit hole :) The reason read() is failing in this case, is because argument clinic defaults the size parameter to -1, which redirects the call to readall(). So this issue is actually about readall(). Calling

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

2019-07-29 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: If your patch can fix the issue with buffering without breaking other things I would be happy to make a review. But OSError and IOError (and several other error types) were merged a long time ago. It can not be undone. -- components: +Library (Lib

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

2019-07-28 Thread David Wilson
David Wilson added the comment: Happy to send a patch for this if we can agree on the semantic being incorrect, and more importantly, someone is happy to review the patch once it reaches GitHub ;) -- ___ Python tracker

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

2019-07-28 Thread David Wilson
New submission from David Wilson : 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, r