You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adds window resizing support to Lib/pty.py [ SIGWINCH ] #85666
This was tested using Python 3.7 after commenting out the sys.audit lines.
https://docs.python.org/3/library/pty.html presents us with an example usage of pty.spawn. This example mimics script(1). However, the script(1) from util-linux has fantastic signal handing that pty.spawn does not directly provide. In fact, Lib/pty.py says "Bugs: No signal handling. Doesn't set slave termios and window size."
xterm(1) on Debian 10 GNU/Linux was used to test the pty.spawn example mentioned above; upon resizing the xterm(1) window, the output of programs such as ls(1) became scattered and hard to visually parse.
This patch does not modify any of the functions that are already present in Lib/pty. Instead, it exposes a new function called "wspawn" [ pty.wspawn ]. This is like pty.spawn + the following differences.
Window size is set at the beginning.
A SIGWINCH handler is registered. The old handler is saved and restored later.
If the above two steps fail, then cleanup is done, and an exception is raised, so that the programmer can catch the exception and use pty.spawn instead.
Unlike pty.spawn, this does not depend on OSError to break out of the parent mainloop. Instead, the main loop calls select with an adjustable timeout, so that waitpid with WNOHANG can be called periodically to check if the spawned child process has undergone an alteration of state.
While the return value is same as that of pty.spawn, this accepts an extra optional "timeout" argument for the select call.
The aforementioned pty.spawn example now works well with window resizing if pty.wspawn is used in place of pty.spawn.
changed the title [-]Add window resizing support [ SIGWINCH ] to Lib/pty[/-][+]Adds window resizing support to Lib/pty.py for proper output rendering[/+]on Aug 8, 2020
changed the title [-]Adds window resizing support to Lib/pty.py for proper output rendering[/-][+]Adds window resizing support to Lib/pty.py[/+]on Aug 8, 2020
changed the title [-]Adds window resizing support to Lib/pty.py for proper output rendering[/-][+]Adds window resizing support to Lib/pty.py[/+]on Aug 8, 2020
Reopening to indicate that this issue has not been resolved. However, this thread should not be used anymore. Use this instead: https://bugs.python.org/issue41818
Activity
8vasu commentedon Aug 6, 2020
This was tested using Python 3.7 after commenting out the sys.audit lines.
https://docs.python.org/3/library/pty.html presents us with an example usage of pty.spawn. This example mimics script(1). However, the script(1) from util-linux has fantastic signal handing that pty.spawn does not directly provide. In fact, Lib/pty.py says "Bugs: No signal handling. Doesn't set slave termios and window size."
xterm(1) on Debian 10 GNU/Linux was used to test the pty.spawn example mentioned above; upon resizing the xterm(1) window, the output of programs such as ls(1) became scattered and hard to visually parse.
This patch does not modify any of the functions that are already present in Lib/pty. Instead, it exposes a new function called "wspawn" [ pty.wspawn ]. This is like pty.spawn + the following differences.
The aforementioned pty.spawn example now works well with window resizing if pty.wspawn is used in place of pty.spawn.
Signed-off-by: Soumendra Ganguly <soumendraganguly@gmail.com>
8vasu commentedon Aug 8, 2020
Updated diff.
Changes _ekill()
[-]Add window resizing support [ SIGWINCH ] to Lib/pty[/-][+]Adds window resizing support to Lib/pty.py for proper output rendering[/+]2 remaining items
[-]Adds window resizing support to Lib/pty.py for proper output rendering[/-][+]Adds window resizing support to Lib/pty.py[/+][-]Adds window resizing support to Lib/pty.py for proper output rendering[/-][+]Adds window resizing support to Lib/pty.py[/+][-]Adds window resizing support to Lib/pty.py[/-][+]Adds window resizing support to Lib/pty.py [ SIGWINCH ][/+][-]Adds window resizing support to Lib/pty.py[/-][+]Adds window resizing support to Lib/pty.py [ SIGWINCH ][/+]8vasu commentedon Aug 9, 2020
Possibly related issues:
https://bugs.python.org/issue29070
https://bugs.python.org/issue26228
Since wspawn does not depend on OSError, it might be a possible [ not necessarily the only way ] of solving the above issues.
8vasu commentedon Aug 13, 2020
Closing because registering SIGWINCH handler from within library function is impractical.
8vasu commentedon Sep 19, 2020
Reopening to indicate that this issue has not been resolved. However, this thread should not be used anymore. Use this instead: https://bugs.python.org/issue41818
ambv commentedon Aug 11, 2021
Thanks, Soumendra. Not resolved but superseded by a different issue has its own indicators on BPO.