-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-26228: Fix pty EOF handling #12049
bpo-26228: Fix pty EOF handling #12049
Conversation
1029c4f
to
3841527
Compare
@eamanu I would love to address your comments and move this closer to being merged, but I don't really understand what you were getting at. If you could provide some clarifications to the questions I asked that would be really helpful. Thanks! |
3841527
to
bc5119e
Compare
ff4cbda
to
03ead99
Compare
@RadicalZephyr: Looks like there are some conflicts with this, would you be able to rebase or otherwise resolve those? @csabella, @gpshead, @vadmium, @eamanu: Do any of y'all see further blockers to this being merged? 🤔 |
03ead99
to
35d6377
Compare
@reillysiemens rebased against master 👍 |
Hi. From 3.10 docs:
This is a result of ALL OSErrors in _copy() being caught in spawn(). However, this patch removes that except clause. I actually like this change :D It is already a part of some code that I have been writing. This way, unwanted OSErrors will not be ignored. However, docs need to be updated. Also, this needs to be approved by reviewers. |
Good catch @8vasu. I've updated the docs a bit to not advertise that throwing Perhaps that whole clause should just be removed instead, and make the usage of spawn returning before the child process ends not officially supported? I think that particular functionality is a very niche use-case that would be abusing |
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. |
I think one of the big concerns with making changes to the existing |
Fantastic idea. I will admit that I have never done this before. If I was to submit a pull request for a new library, I think I would also be responsible for creating docs, tests, etc. Also, if the new library does not modify certain parts of Anyway, I might still make the new library available as a separate download. |
I'm not sure about reusing code from the |
Thank you for the suggestion @RadicalZephyr I will try that first. |
Here you go: https://github.com/8vasu/pypty2 :) I welcome suggestions and criticisms. |
I realized that @reillysiemens is a co-author of this. Since https://github.com/8vasu/pypty2 includes a solution of this issue as well, I should include his name in the Acknowledgements file. Does anyone have any objection? |
Done. |
When both file descriptors gracefully report an error. This presents custom implementations of *master_read* and *stdin_read* that accidentally or intentionally return an empty byte string from blocking the terminal. Co-Authored-By: Reilly Tucker Siemens <reilly@tuckersiemens.com>
a8c7a81
to
9f62b82
Compare
Thanks @RadicalZephyr for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Thanks @RadicalZephyr for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, @RadicalZephyr and @ambv, I could not cleanly backport this to |
GH-27732 is a backport of this pull request to the 3.10 branch. |
On non-Linux POSIX platforms, like FreeBSD or macOS, the FD used to read a forked PTY may signal its exit not by raising an error but by sending empty data to the read syscall. This case wasn't handled, leading to hanging `pty.spawn` calls. Co-authored-by: Reilly Tucker Siemens <reilly@tuckersiemens.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 81ab8db) Co-authored-by: Zephyr Shannon <geoffpshannon@gmail.com>
3.9 differs too much for backporting, leaving this behind then. |
On non-Linux POSIX platforms, like FreeBSD or macOS, the FD used to read a forked PTY may signal its exit not by raising an error but by sending empty data to the read syscall. This case wasn't handled, leading to hanging `pty.spawn` calls. Co-authored-by: Reilly Tucker Siemens <reilly@tuckersiemens.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 81ab8db) Co-authored-by: Zephyr Shannon <geoffpshannon@gmail.com>
Thanks for the fix! I had headaches fighting with https://bugs.python.org/issue38547 See also my commit 7a51a7e for Solaris/AIX: https://bugs.python.org/issue40140 |
I took a shot at fixing this in a smaller more targeted patch. I don't have a BSD system to test this on, but I think this should still solve the major issue of pty.spawn hanging on platforms that don't raise an error. In addition, pty.spawn should now ALWAYS return the terminal to the previous settings.
Co-authored with @reillysiemens.
https://bugs.python.org/issue26228