summaryrefslogtreecommitdiffstats
path: root/Lib/logging
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
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')
-rw-r--r--Lib/logging/__init__.py21
-rw-r--r--Lib/logging/handlers.py23
2 files changed, 27 insertions, 17 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()
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index c67ac99..fda8093 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -627,9 +627,10 @@ class SocketHandler(logging.Handler):
"""
self.acquire()
try:
- if self.sock:
- self.sock.close()
+ sock = self.sock
+ if sock:
self.sock = None
+ sock.close()
logging.Handler.close(self)
finally:
self.release()
@@ -1213,8 +1214,10 @@ class BufferingHandler(logging.Handler):
This version just flushes and chains to the parent class' close().
"""
- self.flush()
- logging.Handler.close(self)
+ try:
+ self.flush()
+ finally:
+ logging.Handler.close(self)
class MemoryHandler(BufferingHandler):
"""
@@ -1268,13 +1271,15 @@ class MemoryHandler(BufferingHandler):
"""
Flush, set the target to None and lose the buffer.
"""
- self.flush()
- self.acquire()
try:
- self.target = None
- BufferingHandler.close(self)
+ self.flush()
finally:
- self.release()
+ self.acquire()
+ try:
+ self.target = None
+ BufferingHandler.close(self)
+ finally:
+ self.release()
class QueueHandler(logging.Handler):