[pypy-commit] pypy default: ignore IOError()s when flushing the files at exit

antocuni noreply at buildbot.pypy.org
Fri Feb 24 10:14:24 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r52836:9f0e8a37712b
Date: 2012-02-24 10:09 +0100
http://bitbucket.org/pypy/pypy/changeset/9f0e8a37712b/

Log:	ignore IOError()s when flushing the files at exit

diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -323,7 +323,12 @@
     def autoflush(self, space):
         w_iobase = self.w_iobase_ref()
         if w_iobase is not None:
-            space.call_method(w_iobase, 'flush') # XXX: ignore IOErrors?
+            try:
+                space.call_method(w_iobase, 'flush')
+            except OperationError, e:
+                # if it's an IOError, ignore it
+                if not e.match(space, space.w_IOError):
+                    raise
         
 
 class AutoFlusher(object):
diff --git a/pypy/module/_io/test/test_fileio.py b/pypy/module/_io/test/test_fileio.py
--- a/pypy/module/_io/test/test_fileio.py
+++ b/pypy/module/_io/test/test_fileio.py
@@ -177,3 +177,20 @@
     """)
     space.finish()
     assert tmpfile.read() == '42'
+
+def test_flush_at_exit_IOError():
+    from pypy import conftest
+    from pypy.tool.option import make_config, make_objspace
+
+    config = make_config(conftest.option)
+    space = make_objspace(config)
+    space.appexec([], """():
+        import io
+        class MyStream(io.IOBase):
+            def flush(self):
+                raise IOError
+
+        s = MyStream()
+        import sys; sys._keepalivesomewhereobscure = s
+    """)
+    space.finish() # the IOError has been ignored


More information about the pypy-commit mailing list