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:
Serhiy Storchaka 2015-04-10 13:29:28 +03:00
commit 2116b12da5
27 changed files with 315 additions and 209 deletions

View file

@ -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