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
13
Lib/sunau.py
13
Lib/sunau.py
|
@ -295,9 +295,11 @@ class Au_read:
|
|||
self._soundpos = pos
|
||||
|
||||
def close(self):
|
||||
if self._opened and self._file:
|
||||
self._file.close()
|
||||
self._file = None
|
||||
file = self._file
|
||||
if file:
|
||||
self._file = None
|
||||
if self._opened:
|
||||
file.close()
|
||||
|
||||
class Au_write:
|
||||
|
||||
|
@ -438,9 +440,10 @@ class Au_write:
|
|||
self._patchheader()
|
||||
self._file.flush()
|
||||
finally:
|
||||
if self._opened and self._file:
|
||||
self._file.close()
|
||||
file = self._file
|
||||
self._file = None
|
||||
if self._opened:
|
||||
file.close()
|
||||
|
||||
#
|
||||
# private methods
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue