mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.10] bpo-42378: fixed log truncation on logging shutdown (GH-27310) (GH-30468)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
This commit is contained in:
parent
ed2656a7d3
commit
e35430bec5
4 changed files with 32 additions and 6 deletions
|
@ -878,6 +878,7 @@ class Handler(Filterer):
|
|||
self._name = None
|
||||
self.level = _checkLevel(level)
|
||||
self.formatter = None
|
||||
self._closed = False
|
||||
# Add the handler to the global _handlerList (for cleanup on shutdown)
|
||||
_addHandlerRef(self)
|
||||
self.createLock()
|
||||
|
@ -996,6 +997,7 @@ class Handler(Filterer):
|
|||
#get the module data lock, as we're updating a shared structure.
|
||||
_acquireLock()
|
||||
try: #unlikely to raise an exception, but you never know...
|
||||
self._closed = True
|
||||
if self._name and self._name in _handlers:
|
||||
del _handlers[self._name]
|
||||
finally:
|
||||
|
@ -1184,6 +1186,8 @@ class FileHandler(StreamHandler):
|
|||
finally:
|
||||
# Issue #19523: call unconditionally to
|
||||
# prevent a handler leak when delay is set
|
||||
# Also see Issue #42378: we also rely on
|
||||
# self._closed being set to True there
|
||||
StreamHandler.close(self)
|
||||
finally:
|
||||
self.release()
|
||||
|
@ -1203,10 +1207,15 @@ class FileHandler(StreamHandler):
|
|||
|
||||
If the stream was not opened because 'delay' was specified in the
|
||||
constructor, open it before calling the superclass's emit.
|
||||
|
||||
If stream is not open, current mode is 'w' and `_closed=True`, record
|
||||
will not be emitted (see Issue #42378).
|
||||
"""
|
||||
if self.stream is None:
|
||||
self.stream = self._open()
|
||||
StreamHandler.emit(self, record)
|
||||
if self.mode != 'w' or not self._closed:
|
||||
self.stream = self._open()
|
||||
if self.stream:
|
||||
StreamHandler.emit(self, record)
|
||||
|
||||
def __repr__(self):
|
||||
level = getLevelName(self.level)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue