Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de6e9d6

Browse files
committed
Issue #9501: Fixed logging regressions in cleanup code.
1 parent 06b8b10 commit de6e9d6

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

Lib/logging/__init__.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,16 @@ def _removeHandlerRef(wr):
609609
"""
610610
Remove a handler reference from the internal cleanup list.
611611
"""
612-
_acquireLock()
613-
try:
614-
if wr in _handlerList:
615-
_handlerList.remove(wr)
616-
finally:
617-
_releaseLock()
612+
# This function can be called during module teardown, when globals are
613+
# set to None. If _acquireLock is None, assume this is the case and do
614+
# nothing.
615+
if _acquireLock is not None:
616+
_acquireLock()
617+
try:
618+
if wr in _handlerList:
619+
_handlerList.remove(wr)
620+
finally:
621+
_releaseLock()
618622

619623
def _addHandlerRef(handler):
620624
"""
@@ -1604,8 +1608,16 @@ def shutdown(handlerList=_handlerList):
16041608
#we just ignore them if raiseExceptions is not set
16051609
try:
16061610
h = wr()
1607-
h.flush()
1608-
h.close()
1611+
if h:
1612+
try:
1613+
h.flush()
1614+
h.close()
1615+
except (IOError, ValueError):
1616+
# Ignore errors which might be caused
1617+
# because handlers have been closed but
1618+
# references to them are still around at
1619+
# application exit.
1620+
pass
16091621
except:
16101622
if raiseExceptions:
16111623
raise

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Extensions
123123
Library
124124
-------
125125

126+
- Issue #9501: Fixed logging regressions in cleanup code.
127+
126128
- Fix functools.total_ordering() to actually work.
127129

128130
- Issue #9572: Importlib should not raise an exception if a directory it

0 commit comments

Comments
 (0)