This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, paul.moore, pitrou, rhettinger, steve.dower, sylikc, tim.golden, zach.ware
Date 2021-04-10.06:05:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618034735.59.0.703389585502.issue43784@roundup.psfhosted.org>
In-reply-to
Content
> my subrocess code doesn't seem to hang on Linux where the 
> thread example code does?

Reader threads for stdout and stderr are only used in Windows, since there's no equivalent to select/poll for synchronous pipes in Windows. 

Without using threads, I/O with synchronous pipes requires a busy loop. It has to poll PeekNamedPipe() to get the number of bytes available to read without blocking. For stdin, on the other hand, the Windows API does not allow getting the WriteQuotaAvailable from the PipeLocalInformation [1]. Without knowing how much can be written without blocking, the input pipe would have to be made non-blocking, which in turn requires an inner loop that tries to write a successively smaller chunk size to stdin until either it succeeds or the size is reduced to 0. 

If we wanted to change communicate() in Windows to not use threads and not require a busy loop, we'd have to switch to using named pipes opened in asynchronous (overlapped) mode on our side of each pipe. But that's an integration problem. For normal use as proc.stdout, etc, we would need an adapter or a new raw file type that implements a synchronous interface by waiting for I/O completion and maintaining its own file pointer. Such files would return the Windows file handle for fileno(), like sockets do, since a C file descriptor requires a synchronous-mode file.

---

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_pipe_local_information
History
Date User Action Args
2021-04-10 06:05:35eryksunsetrecipients: + eryksun, rhettinger, paul.moore, pitrou, tim.golden, zach.ware, steve.dower, sylikc
2021-04-10 06:05:35eryksunsetmessageid: <1618034735.59.0.703389585502.issue43784@roundup.psfhosted.org>
2021-04-10 06:05:35eryksunlinkissue43784 messages
2021-04-10 06:05:35eryksuncreate