diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2011-04-05 13:48:47 (GMT) |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2011-04-05 13:48:47 (GMT) |
commit | 02ba73c0ef4e5b6822b585e99f3bd520e83a1c2e (patch) | |
tree | 583061e85c79fe704370250dce43669cf5447f5c /Lib/subprocess.py | |
parent | 4333affb74f29d46d28ba2b202aa9ff48716cab2 (diff) | |
parent | 4f61b025203cf3fcd52eab2ece0d3f60b0bacd48 (diff) | |
download | cpython-02ba73c0ef4e5b6822b585e99f3bd520e83a1c2e.zip cpython-02ba73c0ef4e5b6822b585e99f3bd520e83a1c2e.tar.gz cpython-02ba73c0ef4e5b6822b585e99f3bd520e83a1c2e.tar.bz2 |
Merge with 3.1
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 039b3e6..b3fb935 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -345,6 +345,7 @@ import gc import signal import builtins import warnings +import errno # Exception classes used by this module. class CalledProcessError(Exception): @@ -376,7 +377,6 @@ if mswindows: else: import select _has_poll = hasattr(select, 'poll') - import errno import fcntl import pickle @@ -785,7 +785,11 @@ class Popen(object): stderr = None if self.stdin: if input: - self.stdin.write(input) + try: + self.stdin.write(input) + except IOError as e: + if e.errno != errno.EPIPE and e.errno != errno.EINVAL: + raise self.stdin.close() elif self.stdout: stdout = self.stdout.read() @@ -1019,7 +1023,11 @@ class Popen(object): if self.stdin: if input is not None: - self.stdin.write(input) + try: + self.stdin.write(input) + except IOError as e: + if e.errno != errno.EPIPE: + raise self.stdin.close() if self.stdout: @@ -1455,9 +1463,16 @@ class Popen(object): for fd, mode in ready: if mode & select.POLLOUT: chunk = input[input_offset : input_offset + _PIPE_BUF] - input_offset += os.write(fd, chunk) - if input_offset >= len(input): - close_unregister_and_remove(fd) + try: + input_offset += os.write(fd, chunk) + except OSError as e: + if e.errno == errno.EPIPE: + close_unregister_and_remove(fd) + else: + raise + else: + if input_offset >= len(input): + close_unregister_and_remove(fd) elif mode & select_POLLIN_POLLPRI: data = os.read(fd, 4096) if not data: @@ -1499,11 +1514,19 @@ class Popen(object): 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 - if input_offset >= len(input): - self.stdin.close() - write_set.remove(self.stdin) + try: + bytes_written = os.write(self.stdin.fileno(), chunk) + except OSError as e: + if e.errno == errno.EPIPE: + self.stdin.close() + write_set.remove(self.stdin) + else: + raise + else: + input_offset += bytes_written + if input_offset >= len(input): + self.stdin.close() + write_set.remove(self.stdin) if self.stdout in rlist: data = os.read(self.stdout.fileno(), 1024) |