mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
Make close() (all versions) ignore IOError from flush().
This makes test_resource.py pass, and I think it's the right thing to do: if you're closing a file after encountering an I/O error there's nothing you can do about it. If you want the error, you can call flush() yourself.
This commit is contained in:
parent
ca73d496ec
commit
33e7a8e813
1 changed files with 11 additions and 4 deletions
15
Lib/io.py
15
Lib/io.py
|
|
@ -229,8 +229,9 @@ class IOBase:
|
||||||
if not self.__closed:
|
if not self.__closed:
|
||||||
try:
|
try:
|
||||||
self.flush()
|
self.flush()
|
||||||
finally:
|
except IOError:
|
||||||
self.__closed = True
|
pass # If flush() fails, just give up
|
||||||
|
self.__closed = True
|
||||||
|
|
||||||
def __del__(self) -> None:
|
def __del__(self) -> None:
|
||||||
"""Destructor. Calls close()."""
|
"""Destructor. Calls close()."""
|
||||||
|
|
@ -598,7 +599,10 @@ class _BufferedIOMixin(BufferedIOBase):
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if not self.closed:
|
if not self.closed:
|
||||||
self.flush()
|
try:
|
||||||
|
self.flush()
|
||||||
|
except IOError:
|
||||||
|
pass # If flush() fails, just give up
|
||||||
self.raw.close()
|
self.raw.close()
|
||||||
|
|
||||||
### Inquiries ###
|
### Inquiries ###
|
||||||
|
|
@ -1048,7 +1052,10 @@ class TextIOWrapper(TextIOBase):
|
||||||
self._telling = self._seekable
|
self._telling = self._seekable
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.flush()
|
try:
|
||||||
|
self.flush()
|
||||||
|
except:
|
||||||
|
pass # If flush() fails, just give up
|
||||||
self.buffer.close()
|
self.buffer.close()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue