diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:41 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:41 (GMT) |
commit | 7e7a3dba5fd4262269f713dfe21ba7e4746fc2dd (patch) | |
tree | a0777a3e70ae76f294fac756c684ec4e24d5df1d /Lib/shelve.py | |
parent | 842f00e72509db50957ceb00d289b305dbc5a0a5 (diff) | |
download | cpython-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.py | 24 |
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'): |