]> granicus.if.org Git - python/commitdiff
Improve issue 7835 fix per MAL to handle the case that the
authorR. David Murray <rdmurray@bitdance.com>
Thu, 11 Feb 2010 01:56:42 +0000 (01:56 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Thu, 11 Feb 2010 01:56:42 +0000 (01:56 +0000)
module dictionary has also been cleared.

Lib/shelve.py

index 8055f42e2291fb4ffa4fac27ab7feb566d0ce4a4..c8cba8582d6ff1ed7a4c7af6e42492fdfca3d13d 100644 (file)
@@ -145,11 +145,12 @@ class Shelf(UserDict.DictMixin):
             self.dict.close()
         except AttributeError:
             pass
-        # _ClosedDict can be None when close is called from __del__ during shutdown
-        if _ClosedDict is None:
-            self.dict = None
-        else:
+        # Catch errors that may happen when close is called from __del__
+        # because CPython is in interpreter shutdown.
+        try:
             self.dict = _ClosedDict()
+        except (NameError, TypeError):
+            self.dict = None
 
     def __del__(self):
         if not hasattr(self, 'writeback'):