From 947da282eed3e79d560bab9e3440548dba83d07d Mon Sep 17 00:00:00 2001 From: shima004 Date: Fri, 6 Dec 2024 00:58:59 +0900 Subject: [PATCH] fix: Set finish_post_connect_event after successful connection and remove redundant logging --- adf_core_python/core/agent/agent.py | 7 +++++++ adf_core_python/core/agent/office/office.py | 1 - adf_core_python/core/agent/platoon/platoon.py | 2 -- adf_core_python/core/launcher/agent_launcher.py | 4 +--- .../core/launcher/connect/component_launcher.py | 3 --- .../core/launcher/connect/connector_ambulance_center.py | 1 - .../core/launcher/connect/connector_ambulance_team.py | 1 - .../core/launcher/connect/connector_fire_brigade.py | 1 - .../core/launcher/connect/connector_fire_station.py | 1 - .../core/launcher/connect/connector_police_force.py | 1 - .../core/launcher/connect/connector_police_office.py | 1 - 11 files changed, 8 insertions(+), 15 deletions(-) diff --git a/adf_core_python/core/agent/agent.py b/adf_core_python/core/agent/agent.py index ec0933c3..55506e1b 100644 --- a/adf_core_python/core/agent/agent.py +++ b/adf_core_python/core/agent/agent.py @@ -238,6 +238,7 @@ def handle_connect_error(self, msg: Any) -> NoReturn: msg.reason, msg.request_id, ) + self.finish_post_connect_event.set() else: self.logger.error( "Failed to connect agent: %s(request_id: %s)", @@ -264,10 +265,16 @@ def handle_connect_ok(self, msg: Any) -> None: self.config.set_value(key, value) self.send_acknowledge(msg.request_id) self.post_connect() + self.logger.info( + f"Connected to kernel: {self.__class__.__qualname__} (request_id: {msg.request_id})", + request_id=msg.request_id, + ) if self.precompute_flag: print("self.precompute_flag: ", self.precompute_flag) self.precompute() + self.finish_post_connect_event.set() + def handler_sense(self, msg: Any) -> None: _id = EntityID(msg.agent_id) time = msg.time diff --git a/adf_core_python/core/agent/office/office.py b/adf_core_python/core/agent/office/office.py index 0aed6bcf..09e97bdd 100644 --- a/adf_core_python/core/agent/office/office.py +++ b/adf_core_python/core/agent/office/office.py @@ -94,7 +94,6 @@ def post_connect(self) -> None: self.precompute_data, self._develop_data, ) - self.finish_post_connect_event.set() def think(self) -> None: self._tactics_center.think( diff --git a/adf_core_python/core/agent/platoon/platoon.py b/adf_core_python/core/agent/platoon/platoon.py index 36c46a6e..c5ff9f89 100644 --- a/adf_core_python/core/agent/platoon/platoon.py +++ b/adf_core_python/core/agent/platoon/platoon.py @@ -96,8 +96,6 @@ def post_connect(self) -> None: self._develop_data, ) - self.finish_post_connect_event.set() - def think(self) -> None: action: Action = self._tactics_agent.think( self._agent_info, diff --git a/adf_core_python/core/launcher/agent_launcher.py b/adf_core_python/core/launcher/agent_launcher.py index f9efa15d..f6f07879 100644 --- a/adf_core_python/core/launcher/agent_launcher.py +++ b/adf_core_python/core/launcher/agent_launcher.py @@ -72,9 +72,7 @@ def connect() -> None: for thread, event in threads.items(): thread.daemon = True thread.start() - is_not_timeout = event.wait(5) - if not is_not_timeout: - break + event.wait(5) connector_thread = threading.Thread(target=connect) connector_thread_list.append(connector_thread) diff --git a/adf_core_python/core/launcher/connect/component_launcher.py b/adf_core_python/core/launcher/connect/component_launcher.py index 8e45009f..0f308c14 100644 --- a/adf_core_python/core/launcher/connect/component_launcher.py +++ b/adf_core_python/core/launcher/connect/component_launcher.py @@ -17,9 +17,6 @@ def make_connection(self) -> Connection: return Connection(self.host, self.port) def connect(self, agent: Agent, _request_id: int) -> None: - self.logger.info( - f"{agent.__class__.__name__} trying to connect to {self.host}:{self.port} request_id: {_request_id}" - ) connection = self.make_connection() try: connection.connect() diff --git a/adf_core_python/core/launcher/connect/connector_ambulance_center.py b/adf_core_python/core/launcher/connect/connector_ambulance_center.py index 1dca5afc..33e736ed 100644 --- a/adf_core_python/core/launcher/connect/connector_ambulance_center.py +++ b/adf_core_python/core/launcher/connect/connector_ambulance_center.py @@ -74,5 +74,4 @@ def connect( ) threads[thread] = finish_post_connect_event - self.logger.info("Connected ambulance center (count: %d)" % count) return threads diff --git a/adf_core_python/core/launcher/connect/connector_ambulance_team.py b/adf_core_python/core/launcher/connect/connector_ambulance_team.py index 879f313d..44620e82 100644 --- a/adf_core_python/core/launcher/connect/connector_ambulance_team.py +++ b/adf_core_python/core/launcher/connect/connector_ambulance_team.py @@ -74,5 +74,4 @@ def connect( ) threads[thread] = finish_post_connect_event - self.logger.info("Connected ambulance team (count: %d)" % count) return threads diff --git a/adf_core_python/core/launcher/connect/connector_fire_brigade.py b/adf_core_python/core/launcher/connect/connector_fire_brigade.py index ac7ecb37..2f5ecf53 100644 --- a/adf_core_python/core/launcher/connect/connector_fire_brigade.py +++ b/adf_core_python/core/launcher/connect/connector_fire_brigade.py @@ -72,5 +72,4 @@ def connect( ) threads[thread] = finish_post_connect_event - self.logger.info("Connected fire brigade (count: %d)" % count) return threads diff --git a/adf_core_python/core/launcher/connect/connector_fire_station.py b/adf_core_python/core/launcher/connect/connector_fire_station.py index de8dbc6b..7efec93e 100644 --- a/adf_core_python/core/launcher/connect/connector_fire_station.py +++ b/adf_core_python/core/launcher/connect/connector_fire_station.py @@ -72,5 +72,4 @@ def connect( ) threads[thread] = finish_post_connect_event - self.logger.info("Connected fire station (count: %d)" % count) return threads diff --git a/adf_core_python/core/launcher/connect/connector_police_force.py b/adf_core_python/core/launcher/connect/connector_police_force.py index d2f45b12..bd291609 100644 --- a/adf_core_python/core/launcher/connect/connector_police_force.py +++ b/adf_core_python/core/launcher/connect/connector_police_force.py @@ -72,5 +72,4 @@ def connect( ) threads[thread] = finish_post_connect_event - self.logger.info("Connected police force (count: %d)" % count) return threads diff --git a/adf_core_python/core/launcher/connect/connector_police_office.py b/adf_core_python/core/launcher/connect/connector_police_office.py index 1c7a7f77..69fd76b0 100644 --- a/adf_core_python/core/launcher/connect/connector_police_office.py +++ b/adf_core_python/core/launcher/connect/connector_police_office.py @@ -74,5 +74,4 @@ def connect( ) threads[thread] = finish_post_connect_event - self.logger.info("Connected police office (count: %d)" % count) return threads