diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-25 21:35:47 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-02-25 21:35:47 (GMT) |
| commit | 6439c00a6dc1a079f7af0d8a44852fa75ece52a6 (patch) | |
| tree | cb0bd75db802878c9f6ba0524d84938bc2062113 /Lib/_pyio.py | |
| parent | 5217d3f9ca3ee5357f9dd9c47cfba04a00596c4a (diff) | |
| download | cpython-6439c00a6dc1a079f7af0d8a44852fa75ece52a6.zip cpython-6439c00a6dc1a079f7af0d8a44852fa75ece52a6.tar.gz cpython-6439c00a6dc1a079f7af0d8a44852fa75ece52a6.tar.bz2 | |
Merged revisions 88610 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r88610 | antoine.pitrou | 2011-02-25 22:24:11 +0100 (ven., 25 févr. 2011) | 4 lines
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 7378f67..dc68d04 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -16,6 +16,7 @@ except ImportError: import io from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END) +from errno import EINTR __metaclass__ = type @@ -937,7 +938,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 @@ -956,7 +962,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 @@ -985,7 +996,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 @@ -1092,7 +1110,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] |
