Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81c87c5

Browse files
committed
Followup to r86383: it seems that in some cases (buildbots), the server
closes the connection before we can call shutdown().
1 parent 1790ed2 commit 81c87c5

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Lib/imaplib.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
__version__ = "2.58"
2424

25-
import binascii, random, re, socket, subprocess, sys, time
25+
import binascii, errno, random, re, socket, subprocess, sys, time
2626

2727
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple",
2828
"Int2AP", "ParseFlags", "Time2Internaldate"]
@@ -260,8 +260,14 @@ def send(self, data):
260260
def shutdown(self):
261261
"""Close I/O established in "open"."""
262262
self.file.close()
263-
self.sock.shutdown(socket.SHUT_RDWR)
264-
self.sock.close()
263+
try:
264+
self.sock.shutdown(socket.SHUT_RDWR)
265+
except socket.error as e:
266+
# The server might already have closed the connection
267+
if e.errno != errno.ENOTCONN:
268+
raise
269+
finally:
270+
self.sock.close()
265271

266272

267273
def socket(self):

0 commit comments

Comments
 (0)