[pypy-commit] pypy default: Retry file.read() and file.write() when they are interrupted by a signal.

amauryfa noreply at buildbot.pypy.org
Thu Sep 13 01:44:08 CEST 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r57311:f89a2c5b6a28
Date: 2012-09-13 01:02 +0200
http://bitbucket.org/pypy/pypy/changeset/f89a2c5b6a28/

Log:	Retry file.read() and file.write() when they are interrupted by a
	signal.

diff --git a/pypy/rlib/streamio.py b/pypy/rlib/streamio.py
--- a/pypy/rlib/streamio.py
+++ b/pypy/rlib/streamio.py
@@ -295,12 +295,23 @@
 
     def read(self, n):
         assert isinstance(n, int)
-        return os.read(self.fd, n)
+        while True:
+            try:
+                return os.read(self.fd, n)
+            except OSError, e:
+                if e.errno != errno.EINTR:
+                    raise
+                # else try again
 
     def write(self, data):
         while data:
-            n = os.write(self.fd, data)
-            data = data[n:]
+            try:
+                n = os.write(self.fd, data)
+            except OSError, e:
+                if e.errno != errno.EINTR:
+                    raise
+            else:
+                data = data[n:]
 
     def close(self):
         os.close(self.fd)


More information about the pypy-commit mailing list