[Python-checkins] r84282 - in python/branches: py3k/Lib/logging/__init__.py py3k/Misc/NEWS release27-maint/Lib/logging/__init__.py release27-maint/Misc/NEWS

vinay.sajip python-checkins at python.org
Mon Aug 23 19:50:31 CEST 2010


Author: vinay.sajip
Date: Mon Aug 23 19:50:30 2010
New Revision: 84282

Log:
Issue #9501: Fixed logging regressions in cleanup code.

Modified:
   python/branches/py3k/Lib/logging/__init__.py
   python/branches/py3k/Misc/NEWS
   python/branches/release27-maint/Lib/logging/__init__.py
   python/branches/release27-maint/Misc/NEWS

Modified: python/branches/py3k/Lib/logging/__init__.py
==============================================================================
--- python/branches/py3k/Lib/logging/__init__.py	(original)
+++ python/branches/py3k/Lib/logging/__init__.py	Mon Aug 23 19:50:30 2010
@@ -609,12 +609,16 @@
     """
     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):
     """
@@ -1604,8 +1608,16 @@
         #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

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Mon Aug 23 19:50:30 2010
@@ -123,6 +123,8 @@
 Library
 -------
 
+- Issue #9501: Fixed logging regressions in cleanup code.
+
 - Fix functools.total_ordering() to actually work.
 
 - Issue #9572: Importlib should not raise an exception if a directory it

Modified: python/branches/release27-maint/Lib/logging/__init__.py
==============================================================================
--- python/branches/release27-maint/Lib/logging/__init__.py	(original)
+++ python/branches/release27-maint/Lib/logging/__init__.py	Mon Aug 23 19:50:30 2010
@@ -617,12 +617,16 @@
     """
     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 @@
         #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

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Mon Aug 23 19:50:30 2010
@@ -31,6 +31,8 @@
 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.)
 


More information about the Python-checkins mailing list