summaryrefslogtreecommitdiffstats
path: root/Lib/ftplib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:10 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-10 10:24:10 (GMT)
commit1aa2c0f073bdbed4fa824591d53e20bbf3d01add (patch)
tree30091bc4164edcf2d192126e5db59392a3078793 /Lib/ftplib.py
parentc26afcc8fce54b8c920c21e2faf1259a92f4aa1f (diff)
downloadcpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.zip
cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.tar.gz
cpython-1aa2c0f073bdbed4fa824591d53e20bbf3d01add.tar.bz2
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.
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r--Lib/ftplib.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index e1c3d99..449ce71 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -594,11 +594,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