From 2a8f21adb0cfb26d0747211b68691cccbd1b5298 Mon Sep 17 00:00:00 2001 From: Max Nigmatulin Date: Tue, 8 Aug 2023 17:53:57 +0300 Subject: [PATCH] View process status when try connecting --- .../connection/broker_conn/socket_manager.py | 20 +++++++++++-------- VSharp.ML.AIAgent/launch_servers.py | 4 +--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/VSharp.ML.AIAgent/connection/broker_conn/socket_manager.py b/VSharp.ML.AIAgent/connection/broker_conn/socket_manager.py index a1931a35d..895d66843 100644 --- a/VSharp.ML.AIAgent/connection/broker_conn/socket_manager.py +++ b/VSharp.ML.AIAgent/connection/broker_conn/socket_manager.py @@ -2,15 +2,16 @@ import time from contextlib import contextmanager, suppress +import psutil import websocket from config import GameServerConnectorConfig -from connection.broker_conn.classes import WSUrl +from connection.broker_conn.classes import ServerInstanceInfo from .requests import acquire_instance, return_instance -def wait_for_connection(url: WSUrl): +def wait_for_connection(server_instance: ServerInstanceInfo): ws = websocket.WebSocket() retries_left = GameServerConnectorConfig.WAIT_FOR_SOCKET_RECONNECTION_MAX_RETRIES @@ -19,22 +20,25 @@ def wait_for_connection(url: WSUrl): with suppress(ConnectionRefusedError, ConnectionResetError): ws.settimeout(GameServerConnectorConfig.CREATE_CONNECTION_TIMEOUT_SEC) ws.connect( - url, skip_utf8_validation=GameServerConnectorConfig.SKIP_UTF_VALIDATION + server_instance.ws_url, + skip_utf8_validation=GameServerConnectorConfig.SKIP_UTF_VALIDATION, ) - if ws.connected: - return ws + # if ws.connected: + # return ws time.sleep(GameServerConnectorConfig.CREATE_CONNECTION_TIMEOUT_SEC) - logging.info(f"Try connecting to {url}, {retries_left} attempts left") + logging.info( + f"Try connecting to {server_instance.ws_url}, {retries_left} attempts left; {psutil.Process(server_instance.pid)}" + ) retries_left -= 1 raise RuntimeError( - f"Retries exsausted wnen trying to connect to {url}: {retries_left} left" + f"Retries exsausted wnen trying to connect to {server_instance.ws_url}: {retries_left} left" ) @contextmanager def game_server_socket_manager(): server_instance = acquire_instance() - socket = wait_for_connection(server_instance.ws_url) + socket = wait_for_connection(server_instance) try: socket.settimeout(GameServerConnectorConfig.RESPONCE_TIMEOUT_SEC) diff --git a/VSharp.ML.AIAgent/launch_servers.py b/VSharp.ML.AIAgent/launch_servers.py index de1a4884c..72719729b 100644 --- a/VSharp.ML.AIAgent/launch_servers.py +++ b/VSharp.ML.AIAgent/launch_servers.py @@ -70,9 +70,7 @@ async def enqueue_instance(request): if wait_for_reset_retries == 0: raise RuntimeError(f"{returned_instance_info} could not be killed") - logging.info( - f"killed {returned_instance_info.pid}, its status: {psutil.Process(returned_instance_info.pid).status()}" - ) + logging.info(f"killed {psutil.Process(returned_instance_info.pid)}") returned_instance_info = run_server_instance( port=returned_instance_info.port, start_server=START_SERVERS )