diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:10 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:10 (GMT) |
commit | 1aa2c0f073bdbed4fa824591d53e20bbf3d01add (patch) | |
tree | 30091bc4164edcf2d192126e5db59392a3078793 /Lib/shelve.py | |
parent | c26afcc8fce54b8c920c21e2faf1259a92f4aa1f (diff) | |
download | cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.zip cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.tar.gz cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.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 c8cba85..4f1e49d 100644 --- a/Lib/shelve.py +++ b/Lib/shelve.py @@ -140,17 +140,21 @@ class Shelf(UserDict.DictMixin): pass 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'): |