def _wait_for_connection(self, port):
connected = False<EOL>max_tries = <NUM_LIT:10><EOL>num_tries = <NUM_LIT:0><EOL>wait_time = <NUM_LIT:0.5><EOL>while not connected or num_tries >= max_tries:<EOL><INDENT>time.sleep(wait_time)<EOL>try:<EOL><INDENT>af = socket.AF_INET<EOL>addr = ('<STR_LIT:127.0.0.1>', port)<EOL>sock = socket.socket(af, socket.SOCK_STREAM)<EOL>sock.connect(addr)<EOL><DEDENT>except socket.error:<EOL><INDENT>if sock:<EOL><INDENT>sock.close()<EOL><DEDENT>num_tries += <NUM_LIT:1><EOL>continue<EOL><DEDENT>connected = True<EOL><DEDENT>if not connected:<EOL><INDENT>print("<STR_LIT>", file=sys.stderr)<EOL><DEDENT>
Wait until we can make a socket connection to sphinx.