[Python-3000-checkins] r56496 - python/branches/py3k-struni/Lib/io.py

guido.van.rossum python-3000-checkins at python.org
Sun Jul 22 22:38:07 CEST 2007


Author: guido.van.rossum
Date: Sun Jul 22 22:38:07 2007
New Revision: 56496

Modified:
   python/branches/py3k-struni/Lib/io.py
Log:
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.


Modified: python/branches/py3k-struni/Lib/io.py
==============================================================================
--- python/branches/py3k-struni/Lib/io.py	(original)
+++ python/branches/py3k-struni/Lib/io.py	Sun Jul 22 22:38:07 2007
@@ -229,8 +229,9 @@
         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 @@
 
     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 @@
         self._telling = self._seekable
 
     def close(self):
-        self.flush()
+        try:
+            self.flush()
+        except:
+            pass  # If flush() fails, just give up
         self.buffer.close()
 
     @property


More information about the Python-3000-checkins mailing list