def METHOD_NAME(proc, host, port, timeout = 600):
    time_limit = time.time() + timeout
    while time.time() < time_limit:
        if proc.poll() is not None:
            raise RuntimeError("Process stopped unexpectedly with return code %d." % proc.poll())
        s = socket.socket()
        try:
            s.connect((host, port))
        except socket.error, e:
            time.sleep(1)
        else:
            break
        finally:
            s.close()
    else:
        raise RuntimeError("Could not connect to process.")