Comment 10 for bug 586359

Revision history for this message
Julian Edwards (julian-edwards) wrote : Re: Virtual builders are sometimes very slow to accept connections

Here's a version that works:

#!/usr/bin/env python
import errno
from socket import socket
import sys

def connect_to_server_until_timeout(host, port, max_tries=10000):
    for i in range(max_tries):
        s = socket()
        result = s.connect_ex((host, port))
        if result == errno.ETIMEDOUT:
            return i
        if result == 0:
            s.close()
    raise RuntimeError("Did not timeout after %s tries" % (i,))

if __name__ == '__main__':
    server = sys.argv[1]
    print connect_to_server_until_timeout(server, 8221)