New submission from Soumendra Ganguly <soumen...@tamu.edu>:

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

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

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

  9. 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 
https://github.com/karelzak/util-linux/commit/1eee1acb245a8b724e441778dfa9b858465bf7e5
 and 
https://github.com/karelzak/util-linux/commit/75ccd75a2fa1194c6415c47b0024a438e26f1ad7#diff-3834a3d25eeaf20d9d0dcb05a46995f6

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

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

----------
components: FreeBSD, Library (Lib), Tests, Windows, macOS
messages: 377195
nosy: koobs, ned.deily, paul.moore, ronaldoussoren, soumendra, steve.dower, 
tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Lib/pty.py major revision
versions: Python 3.10, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41818>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to