diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-12-20 17:55:16 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-12-20 17:55:16 (GMT) |
commit | 4c05969fc41d83e7da9ee3a2e15285a60b68ce23 (patch) | |
tree | c8a4ea23a1f982f788d8b1619d218b009091f3c9 /Lib/_pyio.py | |
parent | 7643c92cdd0e8a3cfd83be9edae3964097b63f0e (diff) | |
parent | 68623614f095c8589ff17c004b9a05c537afc01f (diff) | |
download | cpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.zip cpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.tar.gz cpython-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.tar.bz2 |
merge 3.3 (#16597)
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 7aa43e0..583eb7f 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): |