New submission from Nathaniel Smith <n...@pobox.com>:

So Windows finally has pty support: 
https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/

However, the API is a bit weird. Unlike Unix, when you create a Windows pty, 
there's no way to directly get access to the "slave" handle. Instead, you first 
call CreatePseudoConsole to get a special "HPCON" object, which is similar to a 
Unix pty master. And then you can have to use a special CreateProcess 
incantation to spawn a child process that's attached to our pty.

Specifically, what you have to do is set a special entry in the 
"lpAttributeList", with type "PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE".

Details: 
https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session

Unfortunately, the subprocess module does not provide any way to pass arbitrary 
attributes through lpAttributeList, which means that it's currently impossible 
to use pty support on Windows without reimplementing the whole subprocess 
module.

It would be nice if the subprocess module could somehow support this.

Off the top of my head, I can think of three possible APIs:

Option 1: full support for Windows ptys: this would require wrapping 
CreatePseudoConsole, providing some object to represent a Windows pty, etc. 
This is fairly complex (especially since CreatePseudoConsole requires you to 
pass in some pipe handles, and the user might want to create those themselves).

Option 2: minimal support for Windows ptys: add another supported field to the 
subprocess module's lpAttributeList wrapper, that lets the user pass in an 
"HPCON" cast to a Python integer, and stuffs it into the attribute list. This 
would require users to do all the work to actually *get* the HPCON object, but 
at least it would make ptys possible to use.

Option 3: generic support for unrecognized lpAttributeList entries: add a field 
to the subprocess module's lpAttributeList wrapper that lets you add arbitrary 
entries, specified by type number + arbitrary pointer/chunk of bytes. (Similar 
to how Python's ioctl or setsockopt wrappers work.) Annoyingly, it doesn't seem 
to be enough to just pass in a buffer object, because for pseudoconsole 
support, you actually have to pass in an opaque "HPCON" object directly. (This 
is kind of weird, and might even be a bug, see: 
https://github.com/microsoft/terminal/issues/6705)

----------
messages: 372526
nosy: giampaolo.rodola, gregory.p.smith, njs
priority: normal
severity: normal
status: open
title: Support for new Windows pseudoterminals in the subprocess module
type: enhancement
versions: Python 3.10

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

Reply via email to