Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r53032:f9f3b57f1300
Date: 2012-02-29 22:59 +0100
http://bitbucket.org/pypy/pypy/changeset/f9f3b57f1300/
Log: 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
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
@@ -326,8 +326,11 @@
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
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
@@ -178,7 +178,7 @@
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
@@ -190,7 +190,12 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit