Skip to content

Commit 0e7f894

Browse files
committed
fix: Update logging levels to debug and add finish_post_connect_event parameter in connectors
1 parent 7ea87ef commit 0e7f894

19 files changed

+61
-39
lines changed

adf_core_python/core/agent/agent.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def post_connect(self) -> None:
152152
self._agent_info,
153153
)
154154

155-
self.logger.info(f"config: {self.config}")
155+
self.logger.debug(f"agent_config: {self.config}")
156156

157157
def update_step_info(
158158
self, time: int, change_set: ChangeSet, hear: list[Command]
@@ -297,15 +297,11 @@ def handler_sense(self, msg: Any) -> None:
297297
].intValue,
298298
)
299299
)
300-
start_marge_time = _time.time()
301300
self.world_model.merge(change_set)
302-
end_marge_time = _time.time()
303-
self.logger.debug(
304-
f"Time to merge: {end_marge_time - start_marge_time:.2f} seconds"
305-
)
301+
start_update_info_time = _time.time()
306302
self.update_step_info(time, change_set, heard_commands)
307-
self.logger.info(
308-
f"Time to update_step_info: {_time.time() - end_marge_time:.2f} seconds"
303+
self.logger.debug(
304+
f"{time} step calculation time: {_time.time() - start_update_info_time}"
309305
)
310306

311307
def send_acknowledge(self, request_id: int) -> None:

adf_core_python/core/agent/office/office.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from threading import Event
2+
13
from adf_core_python.core.agent.agent import Agent
24
from adf_core_python.core.agent.config.module_config import ModuleConfig
35
from adf_core_python.core.agent.develop.develop_data import DevelopData
@@ -18,6 +20,7 @@ def __init__(
1820
data_storage_name: str,
1921
module_config: ModuleConfig,
2022
develop_data: DevelopData,
23+
finish_post_connect_event: Event,
2124
) -> None:
2225
super().__init__(
2326
is_precompute,
@@ -27,6 +30,7 @@ def __init__(
2730
data_storage_name,
2831
module_config,
2932
develop_data,
33+
finish_post_connect_event,
3034
)
3135
self._tactics_center = tactics_center
3236
self._team_name = team_name
@@ -90,6 +94,7 @@ def post_connect(self) -> None:
9094
self.precompute_data,
9195
self._develop_data,
9296
)
97+
self.finish_post_connect_event.set()
9398

9499
def think(self) -> None:
95100
self._tactics_center.think(

adf_core_python/core/agent/office/office_ambulance.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from threading import Event
2+
13
from rcrs_core.connection.URN import Entity as EntityURN
24

35
from adf_core_python.core.agent.config.module_config import ModuleConfig
@@ -16,6 +18,7 @@ def __init__(
1618
data_storage_name: str,
1719
module_config: ModuleConfig,
1820
develop_data: DevelopData,
21+
finish_post_connect_event: Event,
1922
) -> None:
2023
super().__init__(
2124
tactics_center,
@@ -25,6 +28,7 @@ def __init__(
2528
data_storage_name,
2629
module_config,
2730
develop_data,
31+
finish_post_connect_event,
2832
)
2933

3034
def precompute(self) -> None:

adf_core_python/core/agent/office/office_fire.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from threading import Event
2+
13
from rcrs_core.connection.URN import Entity as EntityURN
24

35
from adf_core_python.core.agent.config.module_config import ModuleConfig
@@ -16,6 +18,7 @@ def __init__(
1618
data_storage_name: str,
1719
module_config: ModuleConfig,
1820
develop_data: DevelopData,
21+
finish_post_connect_event: Event,
1922
) -> None:
2023
super().__init__(
2124
tactics_center,
@@ -25,6 +28,7 @@ def __init__(
2528
data_storage_name,
2629
module_config,
2730
develop_data,
31+
finish_post_connect_event,
2832
)
2933

3034
def precompute(self) -> None:

adf_core_python/core/agent/office/office_police.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from threading import Event
2+
13
from rcrs_core.connection.URN import Entity as EntityURN
24

35
from adf_core_python.core.agent.config.module_config import ModuleConfig
@@ -16,6 +18,7 @@ def __init__(
1618
data_storage_name: str,
1719
module_config: ModuleConfig,
1820
develop_data: DevelopData,
21+
finish_post_connect_event: Event,
1922
) -> None:
2023
super().__init__(
2124
tactics_center,
@@ -25,6 +28,7 @@ def __init__(
2528
data_storage_name,
2629
module_config,
2730
develop_data,
31+
finish_post_connect_event,
2832
)
2933

3034
def precompute(self) -> None:

adf_core_python/core/agent/platoon/platoon.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ def post_connect(self) -> None:
8888
case Mode.PRECOMPUTED:
8989
pass
9090
case Mode.NON_PRECOMPUTE:
91-
start_time = time.time()
92-
self._logger.info(
93-
f"Prepare start {self._agent_info.get_entity_id().get_value()}"
94-
)
9591
self._tactics_agent.prepare(
9692
self._agent_info,
9793
self._world_info,
@@ -100,7 +96,8 @@ def post_connect(self) -> None:
10096
self.precompute_data,
10197
self._develop_data,
10298
)
103-
self._logger.info(f"Prepare time: {time.time() - start_time:.3f} sec")
99+
100+
self.finish_post_connect_event.set()
104101

105102
def think(self) -> None:
106103
action: Action = self._tactics_agent.think(

adf_core_python/core/component/module/abstract_module.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from abc import ABC, abstractmethod
55
from typing import TYPE_CHECKING
66

7-
from adf_core_python.core.logger.logger import get_logger
7+
from adf_core_python.core.logger.logger import get_agent_logger, get_logger
88

99
if TYPE_CHECKING:
1010
from adf_core_python.core.agent.communication.message_manager import MessageManager
@@ -35,8 +35,9 @@ def __init__(
3535
self._count_prepare: int = 0
3636
self._count_update_info: int = 0
3737
self._count_update_info_current_time: int = 0
38-
self._logger = get_logger(
38+
self._logger = get_agent_logger(
3939
f"{self.__class__.__module__}.{self.__class__.__qualname__}",
40+
self._agent_info,
4041
)
4142

4243
self._sub_modules: list[AbstractModule] = []
@@ -64,8 +65,8 @@ def prepare(self) -> AbstractModule:
6465
for sub_module in self._sub_modules:
6566
start_time = time.time()
6667
sub_module.prepare()
67-
self._logger.info(
68-
f"module {sub_module.__class__.__name__} prepare time: {time.time() - start_time:.3f}",
68+
self._logger.debug(
69+
f"{self.__class__.__name__}'s sub_module {sub_module.__class__.__name__} prepare time: {time.time() - start_time:.3f}",
6970
)
7071
return self
7172

adf_core_python/core/component/tactics/tactics_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ def module_prepare(self) -> None:
133133
for module in self._modules:
134134
start_time = time.time()
135135
module.prepare()
136-
self._logger.info(
136+
self._logger.debug(
137137
f"module {module.__class__.__name__} prepare time: {time.time() - start_time:.3f}",
138138
)
139139
for action in self._actions:
140140
start_time = time.time()
141141
action.prepare()
142-
self._logger.info(
143-
f"action {action.__class__.__name__} prepare time: {time.time() - start_time:.3f}",
142+
self._logger.debug(
143+
f"module {action.__class__.__name__} prepare time: {time.time() - start_time:.3f}",
144144
)
145145
# for executor in self._command_executor:
146146
# executor.prepare()

adf_core_python/core/launcher/agent_launcher.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, config: Config):
3333
self.config = config
3434
self.logger = get_logger(__name__)
3535
self.connectors: list[Connector] = []
36-
self.thread_list: list[threading.Thread] = []
36+
self.agent_thread_list: list[threading.Thread] = []
3737

3838
def init_connector(self) -> None:
3939
loader_name, loader_class_name = self.config.get_value(
@@ -64,13 +64,27 @@ def launch(self) -> None:
6464
host, port, self.logger
6565
)
6666

67+
connector_thread_list: list[threading.Thread] = []
6768
for connector in self.connectors:
6869
threads = connector.connect(component_launcher, self.config, self.loader)
69-
for thread in threads:
70-
thread.daemon = True
71-
thread.start()
72-
time.sleep(0.5)
73-
self.thread_list.extend(threads)
70+
self.agent_thread_list.extend(threads)
7471

75-
for thread in self.thread_list:
72+
def connect():
73+
for thread, event in threads.items():
74+
thread.daemon = True
75+
thread.start()
76+
is_not_timeout = event.wait(5)
77+
if not is_not_timeout:
78+
break
79+
80+
connector_thread = threading.Thread(target=connect)
81+
connector_thread_list.append(connector_thread)
82+
connector_thread.start()
83+
84+
for thread in connector_thread_list:
85+
thread.join()
86+
87+
self.logger.info("All agents have been launched")
88+
89+
for thread in self.agent_thread_list:
7690
thread.join()

adf_core_python/core/launcher/config_key.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ class ConfigKey:
2222
KEY_AMBULANCE_CENTRE_COUNT: Final[str] = "adf.team.office.ambulance.count"
2323
KEY_FIRE_STATION_COUNT: Final[str] = "adf.team.office.fire.count"
2424
KEY_POLICE_OFFICE_COUNT: Final[str] = "adf.team.office.police.count"
25+
# adf-core-python

0 commit comments

Comments
 (0)