Index: Lib/subprocess.py =================================================================== --- Lib/subprocess.py (revision 73994) +++ Lib/subprocess.py (working copy) @@ -369,6 +369,7 @@ import traceback import gc import signal +import errno # Exception classes used by this module. class CalledProcessError(Exception): @@ -414,7 +415,6 @@ else: import select _has_poll = hasattr(select, 'poll') - import errno import fcntl import pickle @@ -918,7 +918,13 @@ if self.stdin: if input is not None: - self.stdin.write(input) + try: + self.stdin.write(input) + except IOError, e: + if e.errno == errno.EPIPE: + pass + else: + raise self.stdin.close() if self.stdout: @@ -1262,7 +1268,13 @@ for fd, mode in ready: if mode & select.POLLOUT: chunk = input[input_offset : input_offset + _PIPE_BUF] - input_offset += os.write(fd, chunk) + try: + input_offset += os.write(fd, chunk) + except OSError, e: + if e.errno == errno.EPIPE: + input_offset = len(input) + else: + raise if input_offset >= len(input): close_unregister_and_remove(fd) elif mode & select_POLLIN_POLLPRI: @@ -1303,8 +1315,13 @@ if self.stdin in wlist: chunk = input[input_offset : input_offset + _PIPE_BUF] - bytes_written = os.write(self.stdin.fileno(), chunk) - input_offset += bytes_written + try: + input_offset += os.write(self.stdin.fileno(), chunk) + except OSError, e: + if e.errno == errno.EPIPE: + input_offset = len(input) + else: + raise if input_offset >= len(input): self.stdin.close() write_set.remove(self.stdin)