def METHOD_NAME() -> int:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(("localhost", 0))
    sock.listen()
    port = sock.getsockname()[1]
    def close_on_accept():
        connection, _ = sock.accept()
        connection.close()
        sock.close()
    threading.Thread(target=close_on_accept, daemon=True).start()
    return port