]> granicus.if.org Git - python/commitdiff
Followup to r86383: it seems that in some cases (buildbots), the server
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 10 Nov 2010 08:59:25 +0000 (08:59 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 10 Nov 2010 08:59:25 +0000 (08:59 +0000)
closes the connection before we can call shutdown().

Lib/imaplib.py

index 94f4e8fdf5def8391cf6beacf6af2ccd81ae9a35..77806db4e145b3f8a05a8f681f232f35ab0ecd0f 100644 (file)
@@ -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):