summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 86f3c4c..ac7832e 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -340,8 +340,10 @@ class IOBase:
This method has no effect if the file is already closed.
"""
if not self.__closed:
- self.flush()
- self.__closed = True
+ try:
+ self.flush()
+ finally:
+ self.__closed = True
def __del__(self):
"""Destructor. Calls close()."""
@@ -1568,8 +1570,10 @@ class TextIOWrapper(TextIOBase):
def close(self):
if self.buffer is not None and not self.closed:
- self.flush()
- self.buffer.close()
+ try:
+ self.flush()
+ finally:
+ self.buffer.close()
@property
def closed(self):