]> granicus.if.org Git - python/commitdiff
[2.7] bpo-21149: Workaround a GC finalization bug in logging. (#4368)
authorGregory P. Smith <greg@krypto.org>
Sat, 11 Nov 2017 22:48:49 +0000 (14:48 -0800)
committerGitHub <noreply@github.com>
Sat, 11 Nov 2017 22:48:49 +0000 (14:48 -0800)
* 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.

Lib/logging/__init__.py
Misc/NEWS.d/next/Library/2017-11-10-17-19-24.bpo-21149.8UVfeT.rst [new file with mode: 0644]

index 22205825f3f38a12b02431e9b1986596742df431..cc24b309009300bd2f386f1d877c3700330c25dc 100644 (file)
@@ -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):
     """
diff --git a/Misc/NEWS.d/next/Library/2017-11-10-17-19-24.bpo-21149.8UVfeT.rst b/Misc/NEWS.d/next/Library/2017-11-10-17-19-24.bpo-21149.8UVfeT.rst
new file mode 100644 (file)
index 0000000..3c582fc
--- /dev/null
@@ -0,0 +1,3 @@
+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.