def main():
    """Wait for ports to start listening."""
    parser = argparse.ArgumentParser(description="Wait for ports to start listening.")
    parser.add_argument("port", type=int, nargs="+")
    parser.add_argument("--timeout", type=int, required=True)
    parser.add_argument("--server-pid", type=int)
    args = parser.parse_args()
    executor = ThreadPoolExecutor(max_workers=len(args.port))
    futures = [
        executor.submit(_wait_for_port, p, args.server_pid, args.timeout)
        for p in args.port
    ]
    for f in as_completed(futures):
        ok, msg = f.result()
        if ok:
            print(f"OK: {msg}")  # noqa: T201
        else:
            print(f"FAIL: {msg}")  # noqa: T201
            exit(1)
Wait for ports to start listening.
scripts/wait_for_listening_port.py