@@ -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 ()
0 commit comments