◐ Shell
reader mode source ↗
Skip to content

bpo-41494: Adds window resizing support to pty.spawn [ SIGWINCH ]#21752

Closed
8vasu wants to merge 4 commits into
python:masterfrom
8vasu:fix-issue-41494
Closed

bpo-41494: Adds window resizing support to pty.spawn [ SIGWINCH ]#21752
8vasu wants to merge 4 commits into
python:masterfrom
8vasu:fix-issue-41494

Conversation

@8vasu

@8vasu 8vasu commented Aug 6, 2020

Copy link
Copy Markdown
Contributor

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.

Currently, this patch does not modify any of the functions that are already present in Lib/pty.py. Instead, it exposes a new function called "wspawn" [ pty.wspawn ]. This is like pty.spawn + the following differences.

  1. Window size is set at the beginning.
  2. A SIGWINCH handler is registered. The old handler is saved and restored later.
  3. 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.
  4. 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. This might be a possible solution to https://bugs.python.org/issue26228, which is mentioned in the docs [ https://docs.python.org/3/library/pty.html ].
  5. 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.

Signed-off-by: Soumendra Ganguly soumendraganguly@gmail.com

https://bugs.python.org/issue41494

@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@8vasu

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@8vasu 8vasu changed the title bpo-41494: Add window resizing support [ SIGWINCH ] to Lib/pty Aug 8, 2020
@8vasu 8vasu changed the title bpo-41494: Add window resizing support [ SIGWINCH ] to Lib/pty.py Aug 8, 2020
@8vasu 8vasu changed the title bpo-41494: Adds window resizing support [ SIGWINCH ] to Lib/pty.py for proper output rendering Aug 8, 2020
@8vasu

8vasu commented Aug 8, 2020

Copy link
Copy Markdown
Contributor Author

@8vasu 8vasu changed the title bpo-41494: Adds window resizing support to Lib/pty.py for proper output rendering Aug 8, 2020
@8vasu 8vasu changed the title bpo-41494: Adds window resizing support to Lib/pty.py Aug 8, 2020
@8vasu

8vasu commented Aug 10, 2020

Copy link
Copy Markdown
Contributor Author

Added detailed comments to the diff.

@8vasu 8vasu changed the title bpo-41494: Adds window resizing support to Lib/pty.py [ SIGWINCH ] Aug 13, 2020
@8vasu 8vasu closed this Aug 13, 2020
@8vasu 8vasu reopened this Sep 19, 2020
@8vasu 8vasu closed this Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants