Eryk Sun added the comment:

Seeing EINVAL here while the child process is alive could mean the read end of 
the pipe was closed. For example:

    >>> import time, subprocess
    >>> cmd = 'python -c "import os, time; os.close(0); time.sleep(15)"'
    >>> p = subprocess.Popen(cmd, stdin=subprocess.PIPE, bufsize=0)
    >>> time.sleep(5); p.communicate(b'spam')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python36\lib\subprocess.py", line 821, in 
communicate
        self._stdin_write(input)
      File "C:\Program Files\Python36\lib\subprocess.py", line 776, in 
_stdin_write
        self.stdin.write(input)
    OSError: [Errno 22] Invalid argument

If buffered, the error would instead occur at self.stdin.close(). Both cases 
are currently checked, but the error is only ignored when the child process is 
still alive.

The underlying Windows error is ERROR_NO_DATA. If we could know that for 
certain, then we could ignore it as a BrokenPipeError. Currently all we have to 
go on from _Py_write is the CRT's EINVAL errno value. In contrast, when 
creating an OSError from the Windows last error value, winerror_to_errno() maps 
ERROR_NO_DATA as EPIPE.

----------
nosy: +eryksun

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

Reply via email to