Skip to content

Commit 00ef7ca

Browse files
authored
Move OnProcessStart from LoadComposableNodes to ComposableNodeContainer (#16)
* Move OnProcessStart from Load to Container This allows LoadComposableNodes to be triggered by some event long after the container process starts. Signed-off-by: Shane Loretz <[email protected]> * remove unused imports Signed-off-by: Shane Loretz <[email protected]> * Document LodeComposableNode must execute after container Signed-off-by: Shane Loretz <[email protected]>
1 parent bf3d800 commit 00ef7ca

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

launch_ros/launch_ros/actions/composable_node_container.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from typing import Optional
1919

2020
from launch.action import Action
21+
from launch.actions import RegisterEventHandler
22+
from launch.event_handlers.on_process_start import OnProcessStart
2123
from launch.launch_context import LaunchContext
2224
from launch.some_substitutions_type import SomeSubstitutionsType
2325

@@ -61,10 +63,20 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]:
6163
load_actions = None # type: Optional[List[Action]]
6264
if self.__composable_node_descriptions is not None:
6365
from .load_composable_nodes import LoadComposableNodes
64-
load_actions = [LoadComposableNodes(
65-
composable_node_descriptions=self.__composable_node_descriptions,
66-
target_container=self
67-
)]
66+
# Perform load action once the container has started.
67+
load_actions = [
68+
RegisterEventHandler(
69+
event_handler=OnProcessStart(
70+
target_action=self,
71+
on_start=[
72+
LoadComposableNodes(
73+
composable_node_descriptions=self.__composable_node_descriptions,
74+
target_container=self
75+
)
76+
]
77+
)
78+
)
79+
]
6880
container_actions = super().execute(context) # type: Optional[List[Action]]
6981
if container_actions is not None and load_actions is not None:
7082
return container_actions + load_actions

launch_ros/launch_ros/actions/load_composable_nodes.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
import composition_interfaces.srv
2121

2222
from launch.action import Action
23-
from launch.actions import RegisterEventHandler
24-
from launch.event_handlers.on_process_start import OnProcessStart
25-
from launch.events.process import ProcessStarted
2623
from launch.launch_context import LaunchContext
2724
import launch.logging
2825
from launch.utilities import ensure_argument_type
@@ -51,6 +48,9 @@ def __init__(
5148
The container node is expected to provide a `~/_container/load_node` service for
5249
loading purposes.
5350
Loading will be performed sequentially.
51+
When executed, this action will block until the container's load service is available.
52+
Make sure any LoadComposableNode action is executed only after its container processes
53+
has started.
5454
5555
:param composable_node_descriptions: descriptions of composable nodes to be loaded
5656
:param target_container: the container to load the nodes into
@@ -156,15 +156,6 @@ def _load_in_sequence(
156156
)
157157
)
158158

159-
def _on_container_start(
160-
self,
161-
event: ProcessStarted,
162-
context: LaunchContext
163-
) -> Optional[List[Action]]:
164-
"""Load nodes on container process start."""
165-
self._load_in_sequence(self.__composable_node_descriptions, context)
166-
return None
167-
168159
def execute(
169160
self,
170161
context: LaunchContext
@@ -176,10 +167,5 @@ def execute(
176167
self.__target_container.node_name
177168
)
178169
)
179-
# Perform load action once the container has started.
180-
return [RegisterEventHandler(
181-
event_handler=OnProcessStart(
182-
target_action=self.__target_container,
183-
on_start=self._on_container_start,
184-
)
185-
)]
170+
# Assume user has configured `LoadComposableNodes` to happen after container action
171+
self._load_in_sequence(self.__composable_node_descriptions, context)

0 commit comments

Comments
 (0)