[New-bugs-announce] [issue26372] Popen.communicate not ignoring BrokenPipeError

Memeplex report at bugs.python.org
Tue Feb 16 20:28:32 EST 2016


New submission from Memeplex:

When not using a timeout, communicate will raise a BrokenPipeError if the command returns an error code. For example:

sp = subprocess.Popen('cat --not-an-option', shell=True, stdin=subprocess.PIPE)
time.sleep(.2)
sp.communicate(b'hi\n')

This isn't consistent with the behavior of communicate with a timeout, which doesn't raise the  exception. Moreover, there is even a comment near the point of the exception stating that communicate must ignore BrokenPipeError:

    def _stdin_write(self, input):
        if input:
            try:
                self.stdin.write(input)
            except BrokenPipeError:
                # communicate() must ignore broken pipe error
                pass
            ....
        self.stdin.close()

Obviously, the problem is that self.stdin.close() is outside the except clause.

----------
components: Library (Lib)
messages: 260373
nosy: memeplex
priority: normal
severity: normal
status: open
title: Popen.communicate not ignoring BrokenPipeError
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26372>
_______________________________________


More information about the New-bugs-announce mailing list