Commit e84f6d38 authored by Gregory P. Smith's avatar Gregory P. Smith Committed by GitHub

[2.7] bpo-21149: Workaround a GC finalization bug in logging. (#4368)

* Work around a GC process finalization bug.

The logging RLock instances may exist but the threading.RLock class
itself has already been emptied causing a
Exception TypeError: "'NoneType' object is not callable" in <function _removeHandlerRef ..."
to be printed to stderr on process termination.

This catches that exception and ignores it because there is absolutely
nothing we can or should do about it from the context of a weakref
handler called from the gc context.
parent 6401e567
......@@ -636,12 +636,19 @@ def _removeHandlerRef(wr):
# to prevent race conditions and failures during interpreter shutdown.
acquire, release, handlers = _acquireLock, _releaseLock, _handlerList
if acquire and release and handlers:
acquire()
try:
if wr in handlers:
handlers.remove(wr)
finally:
release()
acquire()
try:
if wr in handlers:
handlers.remove(wr)
finally:
release()
except TypeError:
# https://bugs.python.org/issue21149 - If the RLock object behind
# acquire() and release() has been partially finalized you may see
# an error about NoneType not being callable. Absolutely nothing
# we can do in this GC during process shutdown situation. Eat it.
pass
def _addHandlerRef(handler):
"""
......
Silence a `'NoneType' object is not callable` in `_removeHandlerRef` error
that could happen when a logging Handler is destroyed as part of cyclic
garbage collection during process shutdown.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment