summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-02-25 21:34:39 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-02-25 21:34:39 (GMT)
commitd843c2d86f3256b9c00bc397ffd490ed0effb71d (patch)
treea718012e8843850a1fe159bd52d286e1ce1cb11f /Lib/_pyio.py
parent31c44031f8daa87afa84fcc1a8ab7f9fc695508d (diff)
downloadcpython-d843c2d86f3256b9c00bc397ffd490ed0effb71d.zip
cpython-d843c2d86f3256b9c00bc397ffd490ed0effb71d.tar.gz
cpython-d843c2d86f3256b9c00bc397ffd490ed0effb71d.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.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index a5d6135..35dea41 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]