Skip to content

Commit

Permalink
Followup to r86383: it seems that in some cases (buildbots), the server
Browse files Browse the repository at this point in the history
closes the connection before we can call shutdown().
  • Loading branch information
pitrou committed Nov 10, 2010
1 parent 1790ed2 commit 81c87c5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Lib/imaplib.py
Expand Up @@ -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"]
Expand Down Expand Up @@ -260,8 +260,14 @@ def send(self, data):
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):
Expand Down

0 comments on commit 81c87c5

Please sign in to comment.