Commits

Antonio Cuni committed 9f0e8a3

ignore IOError()s when flushing the files at exit

  • Participants
  • Parent commits c6b3b1b

Comments (0)

Files changed (2)

pypy/module/_io/interp_iobase.py

     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):

pypy/module/_io/test/test_fileio.py

     """)
     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