summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/io.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 72c9e1785a..ed946659ef 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -227,8 +227,10 @@ class IOBase:
'closed' property (see below) to test.
"""
if not self.__closed:
- self.__closed = True
- self.flush()
+ try:
+ self.flush()
+ finally:
+ self.__closed = True
def __del__(self) -> None:
"""Destructor. Calls close()."""