Rosanswers logo

I'm in the process of migrating a ROS Melodic python node into a ROS 2 Foxy python node. This particular node acts as the state machine for our software stack. It receives a message from another part of the system and, depending on the message, will launch a set of nodes described in a launch file.

Previously in ROS melodic we handled this with:

    uuid = roslaunch.rlutil.get_or_generate_uuid(None, False)
    LAUNCHED_NODES = roslaunch.parent.ROSLaunchParent(uuid, [full_path])

where full_path is the absolute path to a launch file.

Then, when certain conditions are met it will kill these nodes with


Is there a way to do this in ROS 2 Foxy within a Python node? The nodes that get launched can't block the original node from running. I've played around with launch_service, but I can't get it to stop blocking the original node from continuing to execute.

Any tips would be greatly appreciated!

Originally posted by siliconlad on ROS Answers with karma: 11 on 2020-09-07

Post score: 1


1 Answer 1


Rosanswers logo

So the way I ended up solving this problem is by running the ros2 launch command in a Python subprocess:

launch_process = subprocess.Popen(["ros2", "launch", relative_path_to_launch_file], text=True)

Then to kill the nodes, I can simply run


When I posted the question, this wasn't working in Foxy. I think it might've been related to these issues here and here. But it works now. It also works with Galactic.

Originally posted by siliconlad with karma: 11 on 2021-11-09

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.