Skip to content

Instantly share code, notes, and snippets.

@jlblancoc
Created November 11, 2024 08:31
Show Gist options
  • Save jlblancoc/7cf0661e73af1a578007c16438b4a3b5 to your computer and use it in GitHub Desktop.
Save jlblancoc/7cf0661e73af1a578007c16438b4a3b5 to your computer and use it in GitHub Desktop.
ROS2 launch.py: how to make it to quit on a node failure
from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch.actions import (DeclareLaunchArgument,
EmitEvent, LogInfo, RegisterEventHandler)
from launch.event_handlers import OnProcessExit
from launch.events import Shutdown
from ament_index_python import get_package_share_directory
import os
def generate_launch_description():
foo_node = Node(
package='xxxxxxxxx',
executable='xxxxxxxxxx',
name='xxxxxxxx',
output='screen',
parameters=[
{
# 'yyy': LaunchConfiguration('yyy'),
}
],
)
return LaunchDescription([
foo_node,
RegisterEventHandler(
OnProcessExit(
target_action=foo_node,
on_exit=[
LogInfo(msg=('foo_node ended')),
EmitEvent(event=Shutdown(
reason='foo_node ended'))
]
)
)
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment