summaryrefslogtreecommitdiffstats
path: root/Lib/shelve.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:41 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:41 (GMT)
commit7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd (patch)
treea0777a3e70ae76f294fac756c684ec4e24d5df1d /Lib/shelve.py
parent842f00e72509db50957ceb00d289b305dbc5a0a5 (diff)
downloadcpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.zip
cpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.tar.gz
cpython-7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd.tar.bz2
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 cef580e..581baf1 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'):