SSL handshake hanging, despite bugfix in stdlib

Michael Gundlach gundlach at
Sat Jun 23 19:29:37 CEST 2012

Hello, fixed a bug in Python2.6 where SSL's
handshake would hang indefinitely if the remote end hangs.

However, I'm getting hanging behavior in an IMAP script.  When I Ctrl-C it
after hours of hanging, I get the same stacktrace as reported in , though Antoine said that r80452
fixed issue 5103 as well as this bug.

This script sends automatic response emails.  Every 10 seconds it uses IMAP
to check for unread messages in a GMail label, then replies via SMTP and
marks the message as read.  The script seems to work the first time an
unread message is found; the next time there's a message to be had, it
hangs trying to complete the SSL handshake.

  File "./", line 21, in thank_new_signups
    the_emails = list(emails.messages('(UNSEEN)'))
  File "./", line 129, in messages
    for chunk in chunks_of_length(32, messages):
  File "./", line 9, in chunks_of_length
    for item in iterable:
  File "./", line 90, in email_messages
    m = open_mailbox(label, readonly=True)
  File "./", line 30, in open_mailbox
    m = imaplib.IMAP4_SSL('', 993)
  File "/usr/lib64/python2.6/", line 1138, in __init__
    IMAP4.__init__(self, host, port)
  File "/usr/lib64/python2.6/", line 163, in __init__, port)
  File "/usr/lib64/python2.6/", line 1150, in open
    self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
  File "/usr/lib64/python2.6/", line 338, in wrap_socket
  File "/usr/lib64/python2.6/", line 120, in __init__
  File "/usr/lib64/python2.6/", line 279, in do_handshake

(This behavior started only in the last couple of weeks after a longer
period working correctly, so I suspect something changed on GMail's end to
trigger the bug.)

Am I do something wrong, or is this bug still not fixed?  Any pointers
would be appreciated.  Python 2.6.6 (r266:84292, Dec  7 2011, 20:48:22) on
64-bit Linux 2.6.32.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list