summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-11-10 08:59:25 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-11-10 08:59:25 (GMT)
commit81c87c5e9a81728f4c7b022e3786ce11d53ed3c9 (patch)
treef7492bea4d1f4d21689aaf66f6c0841d21f9c71a /Lib
parent1790ed2b2eb7164dd5802c1f9b1b61c406ded8be (diff)
downloadcpython-81c87c5e9a81728f4c7b022e3786ce11d53ed3c9.zip
cpython-81c87c5e9a81728f4c7b022e3786ce11d53ed3c9.tar.gz
cpython-81c87c5e9a81728f4c7b022e3786ce11d53ed3c9.tar.bz2
Followup to r86383: it seems that in some cases (buildbots), the server
closes the connection before we can call shutdown().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/imaplib.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 94f4e8f..77806db 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -22,7 +22,7 @@ Public functions: Internaldate2tuple
__version__ = "2.58"
-import binascii, random, re, socket, subprocess, sys, time
+import binascii, errno, random, re, socket, subprocess, sys, time
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple",
"Int2AP", "ParseFlags", "Time2Internaldate"]
@@ -260,8 +260,14 @@ class IMAP4:
def shutdown(self):
"""Close I/O established in "open"."""
self.file.close()
- self.sock.shutdown(socket.SHUT_RDWR)
- self.sock.close()
+ try:
+ self.sock.shutdown(socket.SHUT_RDWR)
+ except socket.error as e:
+ # The server might already have closed the connection
+ if e.errno != errno.ENOTCONN:
+ raise
+ finally:
+ self.sock.close()
def socket(self):