mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +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:
commit
2116b12da5
27 changed files with 315 additions and 209 deletions
|
|
@ -388,9 +388,11 @@ class HTTPResponse(io.BufferedIOBase):
|
|||
fp.close()
|
||||
|
||||
def close(self):
|
||||
super().close() # set "closed" flag
|
||||
if self.fp:
|
||||
self._close_conn()
|
||||
try:
|
||||
super().close() # set "closed" flag
|
||||
finally:
|
||||
if self.fp:
|
||||
self._close_conn()
|
||||
|
||||
# These implementations are for the benefit of io.BufferedReader.
|
||||
|
||||
|
|
@ -829,13 +831,17 @@ class HTTPConnection:
|
|||
|
||||
def close(self):
|
||||
"""Close the connection to the HTTP server."""
|
||||
if self.sock:
|
||||
self.sock.close() # close it manually... there may be other refs
|
||||
self.sock = None
|
||||
if self.__response:
|
||||
self.__response.close()
|
||||
self.__response = None
|
||||
self.__state = _CS_IDLE
|
||||
try:
|
||||
sock = self.sock
|
||||
if sock:
|
||||
self.sock = None
|
||||
sock.close() # close it manually... there may be other refs
|
||||
finally:
|
||||
response = self.__response
|
||||
if response:
|
||||
self.__response = None
|
||||
response.close()
|
||||
|
||||
def send(self, data):
|
||||
"""Send `data' to the server.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue