[Python-checkins] r86391 - python/branches/py3k/Lib/imaplib.py

antoine.pitrou python-checkins at python.org
Wed Nov 10 09:59:26 CET 2010


Author: antoine.pitrou
Date: Wed Nov 10 09:59:25 2010
New Revision: 86391

Log:
Followup to r86383: it seems that in some cases (buildbots), the server
closes the connection before we can call shutdown().



Modified:
   python/branches/py3k/Lib/imaplib.py

Modified: python/branches/py3k/Lib/imaplib.py
==============================================================================
--- python/branches/py3k/Lib/imaplib.py	(original)
+++ python/branches/py3k/Lib/imaplib.py	Wed Nov 10 09:59:25 2010
@@ -22,7 +22,7 @@
 
 __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 @@
     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):


More information about the Python-checkins mailing list