Commits

Antonio Cuni  committed f9f3b57

ignore also ValueErrors when autoflushing _io files. This is suboptimal, because a ValueError might be an actual bug, but it's the exception which is raised when we try to flush a closed file: this has been reported to happen sometimes with e.g. gzip.GzipFile

  • Participants
  • Parent commits 5c8ac2b

Comments (0)

Files changed (2)

File pypy/module/_io/interp_iobase.py

             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):
+                # if it's an IOError or ValueError, ignore it (ValueError is
+                # raised if by chance we are trying to flush a file which has
+                # already been closed)
+                if not (e.match(space, space.w_IOError) or
+                        e.match(space, space.w_ValueError)):
                     raise
         
 

File pypy/module/_io/test/test_fileio.py

     space.finish()
     assert tmpfile.read() == '42'
 
-def test_flush_at_exit_IOError():
+def test_flush_at_exit_IOError_and_ValueError():
     from pypy import conftest
     from pypy.tool.option import make_config, make_objspace
 
             def flush(self):
                 raise IOError
 
+        class MyStream2(io.IOBase):
+            def flush(self):
+                raise ValueError
+
         s = MyStream()
+        s2 = MyStream2()
         import sys; sys._keepalivesomewhereobscure = s
     """)
     space.finish() # the IOError has been ignored