How can I make ROS2 launch quit on node crash? [closed]

asked 2020-02-10 09:11:09 -0500

allezxandre gravatar image

updated 2020-02-10 18:48:15 -0500

jayess gravatar image

I'm launching multiple nodes using ROS2 launch. I want the whole system to come down if any of the node encounters an exception.

Right now, my launch file looks like this:

from os.path import join

import launch
import launch.actions
import launch.substitutions
import launch_ros.actions
from ament_index_python import get_package_share_directory
from launch.actions import LogInfo
from launch.event_handlers import OnProcessExit

def generate_launch_description():
    emit_shutdown_action = launch.actions.Shutdown(reason='launch is shutting down')
    ld = launch.LaunchDescription([
            # METHOD 1: Node on_exit attribute
            on_exit=[LogInfo(msg=["Node 2 stopped. Stopping everything..."]),
    # METHOD 2: ProcessExit event handler
        on_exit=[LogInfo(msg=["A Node stopped. Stopping everything..."]),

    return ld

Here, I'm trying to effectively catch an unexpected crash of a node in two ways:

  1. through the 'node_2' process on_exit attribute
  2. through the ProcessExit event handler

However, it appears my nodes raising exceptions does not initiate a shut down, and instead, after raising an exception I only receive a log like such:

[ERROR] [node_2]: process has died [pid 11784, exit code 1, cmd '[..]/node_2' ].

indicating that the launch system is aware of my node dying, although no shutdown was triggered.

What should I do to make the launch system shutdown when one of the nodes dies?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by allezxandre
close date 2022-08-17 05:13:18.819941


have you been able to find an answer to your question?

bvaningen gravatar image bvaningen  ( 2022-08-17 05:06:48 -0500 )edit

This was a long time ago so my memory isn't very clear, but I believe an update to ROS2 (probably Foxy) fixed the issue for me

allezxandre gravatar image allezxandre  ( 2022-08-17 05:12:58 -0500 )edit