Eryk Sun <eryk...@gmail.com> added the comment:

I'm changing this to a documentation issue and removing the Windows component. 
The documentation doesn't make it clear that communicate() may block 
indefinitely (in both POSIX and Windows) even after the process has terminated. 
As currently implemented, this claim and the example need to be corrected. 

Depending on one's needs, the Popen() instance can be used as context manager 
to ensure that communication is finalized (e.g. in Windows, the synchronous 
reads in worker threads need to be canceled) and that the pipes are closed -- 
presuming you don't need to read more data after the timeout. If issue 43346 is 
resolved as suggested, then the following will work without blocking 
indefinitely in the second communicate() call:

    proc = subprocess.Popen(...)
    try:
        out, err = proc.communicate(timeout=15)
    except subprocess.TimeoutExpired:
        with proc:
            proc.kill()
        out, err = proc.communicate()

----------
assignee:  -> docs@python
components: +Documentation -Windows
nosy: +docs@python
stage:  -> needs patch

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

Reply via email to