summaryrefslogtreecommitdiff
path: root/Lib/shelve.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/shelve.py')
-rw-r--r--Lib/shelve.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/Lib/shelve.py b/Lib/shelve.py
index 8055f42e22..c8cba8582d 100644
--- a/Lib/shelve.py
+++ b/Lib/shelve.py
@@ -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'):