GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Lib/pty.py major revision · Issue #85984 · python/cpython

Lib/pty.py major revision #85984

New issue
Copy link
New issue
Copy link
Open
Open
Lib/pty.py major revision#85984
Copy link
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifeOS-macOS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dir

Description

8vasu
mannequin
opened on Sep 19, 2020
Issue body actions
BPO 41818
Nosy @gpshead, @pfmoore, @ronaldoussoren, @tjguk, @ned-deily, @encukou, @asvetlov, @zware, @koobs, @zooba, @kulikjak, @aeros, @8vasu
PRs
  • bpo-41818: Updated tests for the standard pty library #22962
  • bpo-41818: test_openpty succeed on Gentoo, don't expect to fail on this platform #23514
  • bpo-41818: Make test_openpty() avoid unexpected success due to number of rows and/or number of columns being == 0. #23526
  • bpo-41818: test_master_read() in test_pty.py should be expected to fail on every platform that is not Linux; that includes Solaris. #23533
  • bpo-41818: Fix test_master_read() so that it succeeds on all platforms that either raise OSError or return b"" upon reading from master #23536
  • bpo-41818: Make additions to the tty module #23546
  • bpo-41818: Add termios.tcgetwinsize(), termios.tcsetwinsize(). Update docs. #23686
  • bpo-41818: Add os.login_tty() for *nix. #23740
  • bpo-41818: Close file descriptors in test_openpty #24119
  • bpo-41818: ++ termios versionadded markers. #27987
  • bpo-41818: Add os.login_tty() for *nix. #29658
  • 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 = None
    created_at = <Date 2020-09-19.23:19:34.173>
    labels = ['OS-mac', '3.8', '3.9', '3.10', 'library', 'tests', 'OS-windows']
    title = 'Lib/pty.py major revision'
    updated_at = <Date 2021-11-20.10:06:35.452>
    user = 'https://github.com/8vasu'

    bugs.python.org fields:

    activity = <Date 2021-11-20.10:06:35.452>
    actor = 'soumendra'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'macOS', 'Tests', 'Windows', 'FreeBSD']
    creation = <Date 2020-09-19.23:19:34.173>
    creator = 'soumendra'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41818
    keywords = ['patch']
    message_count = 22.0
    messages = ['377195', '377198', '377202', '381830', '381839', '381843', '381845', '381847', '381852', '381870', '381922', '381930', '381941', '381965', '381968', '381980', '382016', '384408', '384413', '385257', '400389', '400393']
    nosy_count = 13.0
    nosy_names = ['gregory.p.smith', 'paul.moore', 'ronaldoussoren', 'tim.golden', 'ned.deily', 'petr.viktorin', 'asvetlov', 'zach.ware', 'koobs', 'steve.dower', 'kulikjak', 'aeros', 'soumendra']
    pr_nums = ['22962', '23514', '23526', '23533', '23536', '23546', '23686', '23740', '24119', '27987', '29658']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue41818'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    Linked PRs

    • gh-85984: Remove legacy Lib/pty.py code. #92365
    • gh-85984: Utilize new "winsize" functions from termios in pty tests. #101831
    • gh-85984: New additions and improvements to the tty library. #101832
    • gh-85984: Major revision of the pty library. #101833
    • gh-85984: Add POSIX pseudo-terminal functions. #102413
    • [3.11] gh-85984: Utilize new "winsize" functions from termios in pty tests. (GH-101831) #104652
    • gh-85984: Document change in return type of tty functions #110028
    • [3.12] gh-85984: Document change in return type of tty functions (GH-110028) #110324
    • gh-85984: Add _POSIX_VDISABLE from unistd.h to termios module. #114985
    Reacted by Gregory P. Smith and Piotr Karmelita

    Activity

    Next
    1. 8vasu commented on Sep 19, 2020

      @8vasu
      8vasumannequin
      on Sep 19, 2020
      MannequinAuthor
      More actions

      The current pty library has the following issues:

      1. Does not set slave termios. Documented in the source.

      2. Does not set initial slave window size. Documented in the source. Does not handle SIGWINCH. See bpo-41494, bpo-41541. This is essential in the following practical scenarios: i. creating split windows/panes while using a terminal multiplexer; ii. when resizing GUI terminal emulator window, especially relevant when using tiling window managers; iii. resizing an ansi-term window created inside a GNU Emacs frame.

      3. Does not perform signal handling. Signals must be blocked during sensitive portions of code.

      4. Hangs on FreeBSD. See bpo-26228.

      5. Includes deprecated functions pty.master_open(), pty.slave_open().

      6. In pty.fork(), the fallback code should try using TIOCSCTTY first. It is still using the old method of opening a tty to make it the controlling tty. Currently even SysV based systems provide TIOCSCTTY. See https://stackoverflow.com/questions/51593530/code-explanation-for-glibc-login-tty-function-openttyname-immediately-f

      The current version of pty.spawn() uses pty.fork() internally. However, pty.fork() closes slave and only returns (pid, master_fd). To update winsize, access to slave is necessary. Further, slave termios must be properly set. The proposed modifications do this by implementing a login_tty(3) based function ( tty.login() ), and using that in pty.spawn() instead of pty.fork(). tty.login() tries TIOCSCTTY before falling back to the old SysV method because Python currently does not provide an interface to the native login_tty(3).

      1. tty.setraw() is called right after tty.tcgetattr(). This increases redundancy of code because tty.setraw() itself makes an identical tty.tcgetattr() call.

      2. Requires testing/porting to more platforms. Solaris, Illumos, macOS, Cygwin, etc. Windows ConPTY?

      3. There should be an option in pty.spawn() to turn off slave's ECHO flag. For example, when it is being used in a pipe. See util-linux/util-linux@1eee1ac and util-linux/util-linux@75ccd75#diff-3834a3d25eeaf20d9d0dcb05a46995f6

      4. Tests are incomplete. Tests consider OSes such as Tru64 but not {Free/Net/Open/...}BSD.

      Find ongoing work here: https://github.com/8vasu/pypty2

    2. 8vasu
      added
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      OS-mac
      testsTests in the Lib/test dirTests in the Lib/test dir
      OS-windows
      on Sep 19, 2020
    3. aeros commented on Sep 20, 2020

      @aeros
      aeros
      on Sep 20, 2020
      Contributor
      More actions

      In addition to the above, if a major revision is made to pty, I'd suggest also addressing the issue of "master/slave" terminology, and replace it with something comparable like "parent/child". There's an open devguide issue (python/devguide#605) to more explicitly state terms to avoid, and support for avoiding usage of "slave/master" seems uncontroversial (especially in any new code).

    4. 8vasu commented on Sep 20, 2020

      @8vasu
      8vasumannequin
      on Sep 20, 2020
      MannequinAuthor
      More actions

      Makes sense. I will happily make a change of terminology in the pypty2 repository after the most desirable alternative is determined based on the choice of the majority. I think 'mother/son' sounds cute while still retaining the same initials as before; people used to the older
      terminology will find this easy to remember. Terminology such as parent/child and server/client might make it a little confusing.

    5. asvetlov commented on Nov 25, 2020

      @asvetlov
      asvetlov
      on Nov 25, 2020
      Contributor
      More actions

      New changeset c13d899 by Soumendra Ganguly in branch 'master':
      bpo-41818: Updated tests for the standard pty library (GH-22962)
      c13d899

    6. vstinner commented on Nov 25, 2020

      @vstinner
      vstinner
      on Nov 25, 2020
      Member
      More actions

      This change broke x86 Gentoo buildbots: bpo-42463.

    7. asvetlov commented on Nov 25, 2020

      @asvetlov
      asvetlov
      on Nov 25, 2020
      Contributor
      More actions

      #23514 has the fix, waiting for all buildbots finish before pressing "Merge" button.
      Gentoo bots are green.

    8. 24 remaining items

    9. gpshead
      added a commit that references this issue on May 19, 2023

      gh-85984: New additions and improvements to the tty library. (#101832)

      486bc8e
    10. carljm
      added a commit that references this issue on May 20, 2023

      Merge branch 'main' into gsallam/main

      ea5965a
    11. JelleZijlstra
      added a commit that references this issue on Sep 28, 2023

      pythongh-85984: Document change in return type of tty functions

      4c49b2b
    12. gpshead
      added a commit that references this issue on Oct 4, 2023

      gh-85984: Document change in return type of tty functions (#110028)

      f02f26e
    13. miss-islington
      added a commit that references this issue on Oct 4, 2023

      pythongh-85984: Document change in return type of tty functions (pyth…

      c59cd3b
    14. vstinner
      added a commit that references this issue on Oct 4, 2023

      [3.12] gh-85984: Document change in return type of tty functions (GH-…

      7ec3487
    15. serhiy-storchaka commented on Oct 10, 2023

      @serhiy-storchaka
      serhiy-storchaka
      on Oct 10, 2023
      Member
      More actions

      Why not make cfmakeraw() and cfmakecbreak() returning a new list instead of modifying the input in-place? In any case you need to make a copy, but it is errorprone, because the list contains a nested list. See #110392.

    16. encukou commented on Jan 4, 2024

      @encukou
      encukou
      on Jan 4, 2024
      Member
      More actions

      Regarding "master/slave" terminology:
      I plan to use a strategy I learned at @evildmp's workshop. First, merge #102413, which extends os with a bunch of functions that handle PTY-pairs. There's no simple way to avoid using the inappropriate terms in these functions' docs.
      The merge will make the os docs worse in this respect -- but it'll also make the issue more obvious, and hopefully easier to solve.
      After that I'll propose a PR. Still don't know how that will look, but there's lively brainstorming and style guide recommendations over at the Docs community discord.

      Anyway: @8vasu, feel free to focus on the techincal side, and leave terminology to me.

      Reacted by Soumendra Ganguly
    17. vstinner commented on Jan 8, 2024

      @vstinner
      vstinner
      on Jan 8, 2024
      Member
      More actions

      Regarding "master/slave" terminology

      See also: python/devguide#605 (which was already mentioned previously).

    18. 8vasu commented on Jan 20, 2024

      @8vasu
      8vasu
      on Jan 20, 2024
      ContributorAuthor
      More actions

      I have also commented a variation of this on: #102413

      @vstinner While I am not a CPython maintainer and hence do not have much say in deciding which directions such a prestigious project should take, I am an end user who does pty programming frequently (Python or otherwise) and I will have to deal with the consequences (good or bad) of any decisions taken here.

      I have severe clinical OCD/OCPD and would like to issue a warning here: using generic names like main_fd, second_fd, or parent_fd, child_fd, or server_fd, client_fd will lead to havoc very easily. Just take a look at the source of your very own https://github.com/python/cpython/blob/3.12/Lib/pty.py and try a search/replace involving terms parent/child (already used by processes) or a program like ssh(1) which uses the terms server/client in networking context and also sets up a pty pair.

      On the other hand one can easily have first_fd, second_fd, third_fd or even main_fd in their existing programs. The pair main, subordinate comes to mind, but again, main_fd might be taken and main, subordinate carry the same overtones as master, slave, which is what you are trying to avoid in the first place.

      For a change that is easy to maintain for current and future Python maintainers and eliminates all possibility of confusion for end users when they are referring to documentation, we must use something that is:

      • not already taken to almost absolutely eliminate any chances of variable name collision while
      • maintaining that the initials m and s stay the same.

      Edit:

      Some data: about naming pty-pairs; apart from the file/project/module/documentation-local confusion that inevitably will arise due to using process-specific terminology parent/child; networking-specific terminology server/client, and generic terms main, primary/seconday, here is some global data directly generated using script at the bottom of this post:

      Current timezone and date: Sun Jan 21 06:17:13 AM CET 2024
      Current directory: /tmp/tmp.21-Jan-2024+05:14:25.JZlA6tqeCz
      Temporarily moving into directory: /tmp/tmp.uZECXBwUzE

      Cloning CPython repository...

      Cloning into 'cpython'...
      remote: Enumerating objects: 1004157, done.
      remote: Counting objects: 100% (690/690), done.
      remote: Compressing objects: 100% (425/425), done.
      remote: Total 1004157 (delta 428), reused 448 (delta 265), pack-reused 1003467
      Receiving objects: 100% (1004157/1004157), 549.31 MiB | 5.16 MiB/s, done.
      Resolving deltas: 100% (804152/804152), done.

      Moving into CPython repository...
      /tmp/tmp.uZECXBwUzE/cpython

      Running grep to count number of occurences of concerned terms:

      master: 757 occurences ignoring cases and 727 occurences not ignoring cases
      master_fd: 80 occurences ignoring cases and 80 occurences not ignoring cases
      slave: 155 occurences ignoring cases and 154 occurences not ignoring cases
      slave_fd: 43 occurences ignoring cases and 43 occurences not ignoring cases
      parent: 3760 occurences ignoring cases and 3255 occurences not ignoring cases
      parent_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      child: 5703 occurences ignoring cases and 5067 occurences not ignoring cases
      child_fd: 3 occurences ignoring cases and 3 occurences not ignoring cases
      server: 6237 occurences ignoring cases and 5045 occurences not ignoring cases
      server_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      client: 3036 occurences ignoring cases and 2682 occurences not ignoring cases
      client_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      primary: 378 occurences ignoring cases and 346 occurences not ignoring cases
      primary_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      secondary: 38 occurences ignoring cases and 35 occurences not ignoring cases
      secondary_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      main: 25612 occurences ignoring cases and 24847 occurences not ignoring cases
      main_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      second: 4361 occurences ignoring cases and 3987 occurences not ignoring cases
      second_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      mother: 1 occurences ignoring cases and 1 occurences not ignoring cases
      mother_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases
      (^|[^j])son: 0 occurences ignoring cases and 0 occurences not ignoring cases
      (^|[^j])son_fd: 0 occurences ignoring cases and 0 occurences not ignoring cases

      Removing CPython repository to free up space in /tmp...


      #!/bin/sh -e
      
      l="master master_fd slave slave_fd parent parent_fd \
      child child_fd server server_fd client client_fd primary \
      primary_fd secondary secondary_fd main main_fd second \
      second_fd mother mother_fd (^|[^j])son (^|[^j])son_fd"
      TMP_DIR_PARENT="${1:-/tmp}"
      
      echo "*Current timezone and date:* $(date)"
      echo "*Current directory:* $(pwd)"
      
      # mktemp(1) is not POSIX
      TMP_DIR="$(mktemp -d --tmpdir="$TMP_DIR_PARENT")"
      echo "*Temporarily moving into directory:* $TMP_DIR"
      cd "$TMP_DIR"
      echo
      
      echo "*Cloning CPython repository...*"
      echo
      git clone https://github.com/python/cpython.git
      echo
      echo "*Moving into CPython repository...*"
      cd cpython
      echo
      
      echo "*Running grep to count number of occurences of concerned terms:*"
      echo
      for i in $l
      do
      # "grep -r" is not POSIX
      n="$(grep -r -e $i 2>/dev/null | wc -l)"
      m="$(grep -ri -e $i 2>/dev/null | wc -l)"
      
      echo "\`$i\`: \`$m\` occurences ignoring cases and \`$n\` occurences not ignoring cases"
      done
      
      echo
      echo "*Removing CPython repository to free up space in ${TMP_DIR_PARENT}...*"
      cd ..
      rm -rf ./cpython
    19. encukou
      added a commit that references this issue on Jan 29, 2024

      gh-85984: Add POSIX pseudo-terminal functions. (GH-102413)

      e351ca3
    20. gpshead
      added a commit that references this issue on Feb 11, 2024

      gh-85984: Add _POSIX_VDISABLE from unistd.h to termios module. (#114985)

      bf75f1b
    21. aisk
      added a commit that references this issue on Feb 11, 2024

      pythongh-85984: Add POSIX pseudo-terminal functions. (pythonGH-102413)

      4dd996d
    22. fsc-eriker
      added a commit that references this issue on Feb 14, 2024

      pythongh-85984: Add _POSIX_VDISABLE from unistd.h to termios module. (p…

      9d6c9d8
    23. Glyphack
      added a commit that references this issue on Sep 2, 2024

      pythongh-85984: Document change in return type of tty functions (pyth…

      fc7925e
    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 lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifeOS-macOS-windowsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytestsTests in the Lib/test dirTests in the Lib/test dir

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402503 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.