summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index d1c2806..8388b98 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -750,12 +750,16 @@ class SMTP:
def close(self):
"""Close the connection to the SMTP server."""
- if self.file:
- self.file.close()
- self.file = None
- if self.sock:
- self.sock.close()
- self.sock = None
+ try:
+ file = self.file
+ self.file = None
+ if file:
+ file.close()
+ finally:
+ sock = self.sock
+ self.sock = None
+ if sock:
+ sock.close()
def quit(self):