diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-25 21:24:11 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-25 21:24:11 (GMT) |
commit | 707ce82cabd548b37a4e9e3cf7d9d3cf1eb14c5b (patch) | |
tree | 0464c70d739dddf8a2047ca44f591af562601edd /Lib/_pyio.py | |
parent | 7e1b9af0441acac735742e6f768790cfaa6c672d (diff) | |
download | cpython-707ce82cabd548b37a4e9e3cf7d9d3cf1eb14c5b.zip cpython-707ce82cabd548b37a4e9e3cf7d9d3cf1eb14c5b.tar.gz cpython-707ce82cabd548b37a4e9e3cf7d9d3cf1eb14c5b.tar.bz2 |
Issue #10956: Buffered I/O classes retry reading or writing after a signal
has arrived and the handler returned successfully.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index ad5bfcc..a3b89e7 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -14,6 +14,7 @@ except ImportError: import io from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END) +from errno import EINTR # open() uses st_blksize whenever we can DEFAULT_BUFFER_SIZE = 8 * 1024 # bytes @@ -943,7 +944,12 @@ class BufferedReader(_BufferedIOMixin): current_size = 0 while True: # Read until EOF or until read() would block. - chunk = self.raw.read() + try: + chunk = self.raw.read() + except IOError as e: + if e.errno != EINTR: + raise + continue if chunk in empty_values: nodata_val = chunk break @@ -962,7 +968,12 @@ class BufferedReader(_BufferedIOMixin): chunks = [buf[pos:]] wanted = max(self.buffer_size, n) while avail < n: - chunk = self.raw.read(wanted) + try: + chunk = self.raw.read(wanted) + except IOError as e: + if e.errno != EINTR: + raise + continue if chunk in empty_values: nodata_val = chunk break @@ -991,7 +1002,14 @@ class BufferedReader(_BufferedIOMixin): have = len(self._read_buf) - self._read_pos if have < want or have <= 0: to_read = self.buffer_size - have - current = self.raw.read(to_read) + while True: + try: + current = self.raw.read(to_read) + except IOError as e: + if e.errno != EINTR: + raise + continue + break if current: self._read_buf = self._read_buf[self._read_pos:] + current self._read_pos = 0 @@ -1098,7 +1116,12 @@ class BufferedWriter(_BufferedIOMixin): written = 0 try: while self._write_buf: - n = self.raw.write(self._write_buf) + try: + n = self.raw.write(self._write_buf) + except IOError as e: + if e.errno != EINTR: + raise + continue if n > len(self._write_buf) or n < 0: raise IOError("write() returned incorrect number of bytes") del self._write_buf[:n] |