summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-07-22 20:38:07 (GMT)
committerGuido van Rossum <guido@python.org>2007-07-22 20:38:07 (GMT)
commit33e7a8e8134e90635adb88871defc270e0043073 (patch)
treebff6c8ebe833d833636d4e0791cf72c927766586
parentca73d496ecd5d7addaf3190459e327040958c7a3 (diff)
downloadcpython-33e7a8e8134e90635adb88871defc270e0043073.zip
cpython-33e7a8e8134e90635adb88871defc270e0043073.tar.gz
cpython-33e7a8e8134e90635adb88871defc270e0043073.tar.bz2
Make close() (all versions) ignore IOError from flush().
This makes test_resource.py pass, and I think it's the right thing to do: if you're closing a file after encountering an I/O error there's nothing you can do about it. If you want the error, you can call flush() yourself.
-rw-r--r--Lib/io.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 0054d42..4dfab22 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -229,8 +229,9 @@ class IOBase:
if not self.__closed:
try:
self.flush()
- finally:
- self.__closed = True
+ except IOError:
+ pass # If flush() fails, just give up
+ self.__closed = True
def __del__(self) -> None:
"""Destructor. Calls close()."""
@@ -598,7 +599,10 @@ class _BufferedIOMixin(BufferedIOBase):
def close(self):
if not self.closed:
- self.flush()
+ try:
+ self.flush()
+ except IOError:
+ pass # If flush() fails, just give up
self.raw.close()
### Inquiries ###
@@ -1048,7 +1052,10 @@ class TextIOWrapper(TextIOBase):
self._telling = self._seekable
def close(self):
- self.flush()
+ try:
+ self.flush()
+ except:
+ pass # If flush() fails, just give up
self.buffer.close()
@property