From 5e1c3ce13366ec72b5e9b67d5681266ad93c0ee1 Mon Sep 17 00:00:00 2001
From: Vinay Sajip <vinay_sajip@yahoo.co.uk>
Date: Tue, 15 Jan 2013 17:55:57 +0000
Subject: Issue #9501: Improved shutdown handling to deal with module
 attributes correctly.

---
 Lib/logging/__init__.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 4da07f1..5cb2866 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -711,7 +711,8 @@ def _removeHandlerRef(wr):
     # 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:
+    if (_acquireLock is not None and _handlerList is not None and
+        _releaseLock is not None):
         _acquireLock()
         try:
             if wr in _handlerList:
-- 
cgit v0.12