mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
842f00e725
commit
7e7a3dba5f
27 changed files with 299 additions and 197 deletions
|
@ -138,17 +138,21 @@ class Shelf(collections.MutableMapping):
|
|||
self.close()
|
||||
|
||||
def close(self):
|
||||
self.sync()
|
||||
if self.dict is None:
|
||||
return
|
||||
try:
|
||||
self.dict.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
# 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
|
||||
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'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue