gemini-code-assist[bot] commented on code in PR #19736: URL: https://github.com/apache/tvm/pull/19736#discussion_r3399100939
########## python/tvm/testing/disco.py: ########## @@ -0,0 +1,136 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Testing utilities for the Disco distributed runtime.""" + +# Defer annotation evaluation: `tvm.runtime.disco` is None on builds without +# the disco runtime, and this module must still be importable there. +from __future__ import annotations + +import socket +import subprocess +import sys +import threading + +from tvm.runtime import disco as di + +_SOCKET_SESSION_TESTER = None + + +def _get_free_port() -> int: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.bind(("", 0)) + port = sock.getsockname()[1] + sock.close() + return port + + +class SocketSessionTester: + """Run a disco SocketSession with one local node and remote nodes. + + Each remote node is a `tvm.exec.disco_remote_socket_session` subprocess + launched with the current Python interpreter. + """ + + def __init__(self, num_workers, num_nodes=2, num_groups=1): + # Initialize the attributes used by __del__ first, so that teardown is + # safe even when __init__ raises below. + self.sess = None + self.remote_nodes = [] + assert num_workers % num_nodes == 0 + num_workers_per_node = num_workers // num_nodes + server_host = "localhost" + server_port = _get_free_port() + server_exc = [] + + def start_server(): + try: + self.sess = di.SocketSession( + num_nodes, num_workers_per_node, num_groups, server_host, server_port + ) + except Exception as exc: # pylint: disable=broad-except + server_exc.append(exc) + + thread = threading.Thread(target=start_server) + thread.start() Review Comment:  The server thread is not configured as a daemon thread. If the main thread or any subprocess fails or exits with an exception, this non-daemon thread can block indefinitely and prevent the test process from exiting, leading to CI hangs. Setting `daemon=True` ensures the thread does not block process exit. ```suggestion thread = threading.Thread(target=start_server, daemon=True) thread.start() ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
