]> granicus.if.org Git - python/commitdiff
Issue #9501: Fixed logging regressions in cleanup code.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 23 Aug 2010 17:50:30 +0000 (17:50 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 23 Aug 2010 17:50:30 +0000 (17:50 +0000)
Lib/logging/__init__.py
Misc/NEWS

index 80ec6724e44c3d091e6120a6eeebfa47aecc1907..5922ed3295f29f63e402a7b2368caf00a34e07ed 100644 (file)
@@ -617,12 +617,16 @@ def _removeHandlerRef(wr):
     """
     Remove a handler reference from the internal cleanup list.
     """
-    _acquireLock()
-    try:
-        if wr in _handlerList:
-            _handlerList.remove(wr)
-    finally:
-        _releaseLock()
+    # This function can be called during module teardown, when globals are
+    # set to None. If _acquireLock is None, assume this is the case and do
+    # nothing.
+    if _acquireLock is not None:
+        _acquireLock()
+        try:
+            if wr in _handlerList:
+                _handlerList.remove(wr)
+        finally:
+            _releaseLock()
 
 def _addHandlerRef(handler):
     """
@@ -1612,8 +1616,16 @@ def shutdown(handlerList=_handlerList):
         #we just ignore them if raiseExceptions is not set
         try:
             h = wr()
-            h.flush()
-            h.close()
+            if h:
+                try:
+                    h.flush()
+                    h.close()
+                except (IOError, ValueError):
+                    # Ignore errors which might be caused
+                    # because handlers have been closed but
+                    # references to them are still around at
+                    # application exit.
+                    pass
         except:
             if raiseExceptions:
                 raise
index d4fb9f2927c482a577039c165418e45b1e775153..ed9c1924811a3fc2c47ad3aa05789e3bb1a42d8c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #9501: Fixed logging regressions in cleanup code.
+
 - Issue #9214: Set operations on KeysView or ItemsView in the collections
   module now correctly return a set.  (Patch by Eli Bendersky.)