Skip to content

Adds window resizing support to Lib/pty.py [ SIGWINCH ] #85666

Closed

Description

@8vasu
mannequin
BPO 41494
Nosy @ambv, @8vasu
PRs
  • bpo-41494: Adds window resizing support to pty.spawn [ SIGWINCH ] #21752
  • Superseder
  • bpo-41818: Lib/pty.py major revision
  • Files
  • pty.diff: v0.1
  • pty.diff: v0.2
  • 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:

    assignee = None
    closed_at = <Date 2021-08-11.14:26:18.624>
    created_at = <Date 2020-08-06.11:10:23.164>
    labels = ['3.7', '3.8', '3.9', '3.10', 'type-feature', 'library']
    title = 'Adds window resizing support to Lib/pty.py [ SIGWINCH ]'
    updated_at = <Date 2021-08-11.14:26:18.623>
    user = 'https://github.com/8vasu'

    bugs.python.org fields:

    activity = <Date 2021-08-11.14:26:18.623>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-08-11.14:26:18.624>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2020-08-06.11:10:23.164>
    creator = 'soumendra'
    dependencies = []
    files = ['49372', '49376']
    hgrepos = []
    issue_num = 41494
    keywords = ['patch']
    message_count = 7.0
    messages = ['374926', '375025', '375044', '375086', '375314', '377196', '399395']
    nosy_count = 2.0
    nosy_names = ['lukasz.langa', 'soumendra']
    pr_nums = ['21752']
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = '41818'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41494'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    Activity

    1. 8vasu commented on Aug 6, 2020

      8vasumannequin
      MannequinAuthor

      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.

      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.
      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>

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Aug 6, 2020
    3. 8vasu commented on Aug 8, 2020

      8vasumannequin
      MannequinAuthor

      Updated diff.

      Changes _ekill()

    4. 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
    5. 2 remaining items

    6. 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
    7. 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
    8. changed the title [-]Adds window resizing support to Lib/pty.py[/-] [+]Adds window resizing support to Lib/pty.py [ SIGWINCH ][/+] on Aug 8, 2020
    9. changed the title [-]Adds window resizing support to Lib/pty.py[/-] [+]Adds window resizing support to Lib/pty.py [ SIGWINCH ][/+] on Aug 8, 2020
    10. 8vasu commented on Aug 9, 2020

      8vasumannequin
      MannequinAuthor

      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.

    11. 8vasu commented on Aug 13, 2020

      8vasumannequin
      MannequinAuthor

      Closing because registering SIGWINCH handler from within library function is impractical.

    12. 8vasu commented on Sep 19, 2020

      8vasumannequin
      MannequinAuthor

      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

    13. reopened this on Sep 19, 2020
    14. reopened this on Sep 19, 2020
    15. ambv commented on Aug 11, 2021

      @ambv
      Contributor

      Thanks, Soumendra. Not resolved but superseded by a different issue has its own indicators on BPO.

    16. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.7 (EOL)end of life3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions