bpo-26228: Fix pty EOF handling by RadicalZephyr · Pull Request #12049 · python/cpython (original) (raw)
Agreed. In fact, if the child process does not change state, even if you successfully get out of _copy(), you'll still be stuck at the final waitpid() in spawn() [ this is off the top of my head; I have not tested this claim, so please correct me if I am wrong. ]
Anyway, there are several other problems with cpython's pty. A lot of its fallback code is outdated; I contacted the glibc people about this. I am currently using a tiling window manager; every time I resize xterm's X window, the underlying terminal size also gets modified, and the output of commands are laid out incorrectly, making them very hard to read [ no SIGWINCH handling ].
There are much better pty libraries for python on PyPI, but when I want to perform a quick test, I should not have to download and learn how to use third party libraries. I have fixed most of these issues in cpython's pty while keeping it backward compatible: I decided to keep the "except OSError" in spawn() for now. I tested my version on Linux, FreeBSD, OpenBSD, and NetBSD. I have not tested it on Solaris, Illumos, macOS, Cygwin, etc. However, I am afraid that cpython will probably take a decade to merge such changes, given that its primary objective is not systems programming :D After a little more testing, I will make the file available in a separate repository; it will serve as an independent drop-in replacement for cpython's pty.