Repository navigation
[PATCH] Make pty.spawn set window size #85713
Description
Activity
The example in https://docs.python.org/3/library/pty.html that mimics script(1) can be used to reproduce the problem: since window size is not set by pty.spawn, output of "ls" becomes scattered and hard to visually parse if xterm window is not in fullscreen mode.
To fix the above issue, this patch makes pty.spawn set window size ( TIOCSWINSZ ). Also, this patch makes the code of pty.fork() more readable by defining _login_pty(); the latter is reused in spawn().
- added3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Aug 13, 2020 - changed the title
[-]Make pty.spawn set window size, make code more readable[/-][+]Make pty.spawn set window size[/+]on Aug 13, 2020 - changed the title
[-]Make pty.spawn set window size, make code more readable[/-][+]Make pty.spawn set window size[/+]on Aug 13, 2020 OS: Linux 4.19.0-9-amd64 Debian 10 GNU/Linux
Note that defining _login_pty() was not a cosmetic change; it is reused in spawn().
8 remaining items
I am new to BPO. Just learned how to make someone nosy.
@twouters, I have attached all resources. This is ready for a review.
Thank you.
Additional note: I am using the i3wm window manager. No desktop environment.
- changed the title
[-]Make pty.spawn set window size [ patch + before, after screenshots ][/-][+][PATCH] Make pty.spawn set window size[/+]on Aug 15, 2020 - changed the title
[-]Make pty.spawn set window size [ patch + before, after screenshots ][/-][+][PATCH] Make pty.spawn set window size[/+]on Aug 15, 2020 v0.3 removes _login_pty() and defines _login_tty() instead; the latter is based on login_tty(3) from glibc.
v0.4 puts try-except guards around imports so that existing code does not break.
Further proposal: Rename my _login_tty to login_tty and make it available as a part of the pty library. Note that usually login_tty accompanies openpty and forkpty on a system; for example, see
https://www.man7.org/linux/man-pages/man3/login_tty.3.html
https://man.openbsd.org/login_tty
https://netbsd.gw.com/cgi-bin/man-cgi?login_tty++NetBSD-currentHowever, python's pty only offers openpty and forkpty in the form of pty.openpty and pty.fork respectively. While it is true that forkpty [ pty.fork ] combines openpty, fork, and login_tty, it also closes the slave end of the pty, making it unsuitable for situations where the slave end needs to be kept open; for example, in my patch, the slave end is used to set the window size; or, in case someone wants to do even better and register a SIGWINCH handler for situations in which the window size can change.
Further note: login_tty will also enable us to set slave termios from the parent process in pty.spawn.
Due to the fact that reviewing patches can be overwhelming, v0.5 removes a lot of stuff and instead simply performs window resize by calling ioctl TIOCSWINSZ on the master end of the pty. Still works as expected.
v0.5 had introduced minor mistakes + one hack [ was using master instead of slave to set window size ]. v0.6 removes all such mistakes.
All images, test programs, and old patches have been removed.
window resize test is now being performed using stty.
On linux:
stty -F <terminal-device-file> rows x cols yOn BSDs:
stty -f <terminal-device-file> rows x cols yto change window size.
Any reason this was dropped? Anyway the patch was useful for me.
@kjoyce77 This was opened as "proof of concept" and was a dirty quick fix (not supposed to be merged). Please comment here instead: #85984. The core developers are very busy (I am not a core developer), and they do the best they can when they get time to review our pull requests. Please help them review my pull requests on that thread if you have time!
Superseded by #85984. Let's get that one in :)
Reacted by Soumendra Ganguly
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: