mirror of
https://github.com/python/cpython.git
synced 2025-09-24 09:23:02 +00:00
call close on the underlying stream even if flush raises (#16597)
This commit is contained in:
parent
bacf1bf355
commit
a2d6d7121e
4 changed files with 68 additions and 13 deletions
12
Lib/_pyio.py
12
Lib/_pyio.py
|
@ -340,8 +340,10 @@ class IOBase:
|
|||
This method has no effect if the file is already closed.
|
||||
"""
|
||||
if not self.__closed:
|
||||
self.flush()
|
||||
self.__closed = True
|
||||
try:
|
||||
self.flush()
|
||||
finally:
|
||||
self.__closed = True
|
||||
|
||||
def __del__(self):
|
||||
"""Destructor. Calls close()."""
|
||||
|
@ -1568,8 +1570,10 @@ class TextIOWrapper(TextIOBase):
|
|||
|
||||
def close(self):
|
||||
if self.buffer is not None and not self.closed:
|
||||
self.flush()
|
||||
self.buffer.close()
|
||||
try:
|
||||
self.flush()
|
||||
finally:
|
||||
self.buffer.close()
|
||||
|
||||
@property
|
||||
def closed(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue