@@ -42,12 +42,16 @@ def setup(self, config: EnvironmentConfig | None = None) -> None:
4242 self .state_node = state_node .StateNode (self .autoware_state )
4343 self .autoware_node = autoware_node .AutowareNode (self .autoware_state )
4444
45- self ._nodes = [self .route_node , self .autoware_node , self .state_node ]
46- self ._node_threads = [
47- threading .Thread (target = rclpy .spin , args = (self .route_node )),
48- threading .Thread (target = rclpy .spin , args = (self .autoware_node )),
49- threading .Thread (target = rclpy .spin , args = (self .state_node )),
50- ]
45+ self ._multi_thread_executor = rclpy .executor .MultiThreadedExecutor ()
46+
47+ self ._multi_thread_executor .add (self .route_node )
48+ self ._multi_thread_executor .add (self .state_node )
49+ self ._multi_thread_executor .add (self .autoware_node )
50+
51+ self ._executor_thread = threading .Thread (
52+ target = self ._multi_thread_executor .spin , daemon = True
53+ )
54+ self ._executor_thread .start ()
5155
5256 # check the bridge is ready
5357 # publish sensor information to the bridge
@@ -105,14 +109,14 @@ def _convert_to_waypoint(self, point):
105109 def destroy (self ) -> None :
106110 """Cleanup"""
107111 try :
108- for thread in range (len (self ._node_threads )):
109- self ._node_threads [thread ].join ()
110- self ._nodes [thread ].destroy_node ()
112+ self .autoware_node .destroy ()
113+ self .state_node .destroy ()
114+ self .route_node .destroy ()
115+ rclpy .shutdown ()
116+ self ._executor_thread .join ()
111117 except RuntimeError :
112118 logger .info ("Cleaned up threads..." )
113119
114- rclpy .shutdown ()
115-
116120 def run_step (self ) -> None :
117121 """Tick method containing all logic based on autoware state"""
118122 self .counter += 1
0 commit comments