mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +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
|
|
@ -667,11 +667,16 @@ class FTP:
|
|||
|
||||
def close(self):
|
||||
'''Close the connection without assuming anything about it.'''
|
||||
if self.file is not None:
|
||||
self.file.close()
|
||||
if self.sock is not None:
|
||||
self.sock.close()
|
||||
self.file = self.sock = None
|
||||
try:
|
||||
file = self.file
|
||||
self.file = None
|
||||
if file is not None:
|
||||
file.close()
|
||||
finally:
|
||||
sock = self.sock
|
||||
self.sock = None
|
||||
if sock is not None:
|
||||
sock.close()
|
||||
|
||||
try:
|
||||
import ssl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue