diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:10 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-10 10:24:10 (GMT) |
commit | 1aa2c0f073bdbed4fa824591d53e20bbf3d01add (patch) | |
tree | 30091bc4164edcf2d192126e5db59392a3078793 /Lib/smtplib.py | |
parent | c26afcc8fce54b8c920c21e2faf1259a92f4aa1f (diff) | |
download | cpython-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/smtplib.py')
-rwxr-xr-x | Lib/smtplib.py | 16 |
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): |