* 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.
# 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):
"""
--- /dev/null
+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.