summaryrefslogtreecommitdiffstats
path: root/Lib/logging/__init__.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:41 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:41 (GMT)
commit7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd (patch)
treea0777a3e70ae76f294fac756c684ec4e24d5df1d /Lib/logging/__init__.py
parent842f00e72509db50957ceb00d289b305dbc5a0a5 (diff)
downloadcpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.zip
cpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.tar.gz
cpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.tar.bz2
Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released even if errors are occured.
Diffstat (limited to 'Lib/logging/__init__.py')
-rw-r--r--Lib/logging/__init__.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index e866b96..67d9d2e 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1011,14 +1011,19 @@ class FileHandler(StreamHandler):
"""
self.acquire()
try:
- if self.stream:
- self.flush()
- if hasattr(self.stream, "close"):
- self.stream.close()
- self.stream = None
- # Issue #19523: call unconditionally to
- # prevent a handler leak when delay is set
- StreamHandler.close(self)
+ try:
+ if self.stream:
+ try:
+ self.flush()
+ finally:
+ stream = self.stream
+ self.stream = None
+ if hasattr(stream, "close"):
+ stream.close()
+ finally:
+ # Issue #19523: call unconditionally to
+ # prevent a handler leak when delay is set
+ StreamHandler.close(self)
finally:
self.release()