aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-12-20 11:55:16 -0600
committerBenjamin Peterson <benjamin@python.org>2012-12-20 11:55:16 -0600
commit4c05969fc41d83e7da9ee3a2e15285a60b68ce23 (patch)
treec8a4ea23a1f982f788d8b1619d218b009091f3c9 /Lib/_pyio.py
parentmerge 3.3 (#16722) (diff)
parentcall close on the underlying stream even if flush raises (closes #16597) (diff)
downloadcpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.tar.gz
cpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.tar.bz2
cpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.zip
merge 3.3 (#16597)
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 7aa43e00221..583eb7f2620 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -346,8 +346,10 @@ class IOBase(metaclass=abc.ABCMeta):
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()."""
@@ -1584,8 +1586,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):