summaryrefslogtreecommitdiff
path: root/Lib/shelve.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-10 13:29:28 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-10 13:29:28 +0300
commit2116b12da59f77358cc539b90f58a3cdea43c2fd (patch)
tree693d26652b1dbf8b2ac058c5725f9726c3d14a0b /Lib/shelve.py
parentfcbf8f3e3d46eb023dd9a3954c6f9ed9a533d427 (diff)
parent7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd (diff)
downloadcpython-git-2116b12da59f77358cc539b90f58a3cdea43c2fd.tar.gz
Issue #23865: close() methods in multiple modules now are idempotent and more
robust at shutdown. If needs to release multiple resources, they are released even if errors are occured.
Diffstat (limited to 'Lib/shelve.py')
-rw-r--r--Lib/shelve.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/Lib/shelve.py b/Lib/shelve.py
index cef580e5cd..581baf1e6f 100644
--- a/Lib/shelve.py
+++ b/Lib/shelve.py
@@ -138,17 +138,21 @@ class Shelf(collections.MutableMapping):
self.close()
def close(self):
- self.sync()
- try:
- self.dict.close()
- except AttributeError:
- pass
- # Catch errors that may happen when close is called from __del__
- # because CPython is in interpreter shutdown.
+ if self.dict is None:
+ return
try:
- self.dict = _ClosedDict()
- except (NameError, TypeError):
- self.dict = None
+ self.sync()
+ try:
+ self.dict.close()
+ except AttributeError:
+ pass
+ finally:
+ # Catch errors that may happen when close is called from __del__
+ # because CPython is in interpreter shutdown.
+ try:
+ self.dict = _ClosedDict()
+ except:
+ self.dict = None
def __del__(self):
if not hasattr(self, 'writeback'):