Eryk Sun added the comment:
> Python already has a multiprocessing module which is able to pass
> handles (maybe also FD? I don't know) to child processes on
> Windows.
Popen doesn't implement the undocumented CRT protocol that's used to smuggle
the file-descriptor mapping in the STARTUPINFO cbReserved2 and lpReserved2
fields. This is a feature of the CRT's spawn and exec functions. For example:
fdr, fdw = os.pipe()
os.set_inheritable(fdw, True)
os.spawnl(os.P_WAIT, os.environ['ComSpec'], 'cmd /c "echo spam >&%d"' % fdw)
>>> os.read(fdr, 10)
b'spam \r\n'
We don't have to worry about implementing fd inheritance so long as os.spawn*
uses the CRT. Someone that needs this functionality can simply be instructed to
use os.spawn.
> I dislike adding a lpAttributeList attribute: it's too close to
> the exact implementation of Windows may change in the future.
If you're going to worry about lpAttributeList, why stop there?
Aren't dwFlags, wShowWindow, hStdInput, hStdOutput, and hStdError also too
close to the exact implementation? My thoughts when suggesting this were
actually to make this as close to the underlying API as possible, and
extensible to support other attributes if there's a demand for it.
Passing a list of handles is atypical usage, and since Python and subprocess
use file descriptors instead of Windows handles, I prefer isolating this in a
Windows structure such as STARTUPINFO, rather than adding even more confusion
to Popen's constructor.
> Since the only known use case today is to pass handles
In the review of the first patch, I listed 3 additional attributes that might
be useful to add in 3.7: IDEAL_PROCESSOR, GROUP_AFFINITY, and PREFERRED_NODE
(simplified by the fact that 3.7 no longer supports Vista). Currently the way
to set the latter two is to use the built-in `start` command of the cmd shell.
> I propose to focus on this use case: add a new pass_handles parameter
> to Popen, similar to pass_fds.
This is a messy situation. Python 3's file I/O is built on the CRT's POSIX
layer. If it had been implemented directly on the Windows API using handles,
then pass_fds would obviously use handles. That's the current situation with
socket module because Winsock makes no attempt to hide AFD handles behind POSIX
file descriptors.
Popen's constructor accepts file descriptors -- not Windows handles -- for its
stdin, stdout, and stderr arguments, and the parameter to control inheritance
is named "close_fds". It seems out of place to add a "pass_handles" parameter.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19764>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com