Errors running LaunchService unsing threading/multiprocessing.

asked 2018-12-20 10:30:54 -0500

nzlz gravatar image

updated 2018-12-21 02:27:31 -0500

Hi everyone,

Im kind of replicating some examples (for instance, this one) and trying to run the ros2 LaunchService in a new thread or process. My objective is that I keep the launched nodes active while my python script is able to continue its normal execution, which consists in communicating with those nodes.

Right now using threading is not viable since I get many errors, possibly related to python3.6 as I have read. So I am using multiprocessing/Process.

The LaunchDescrioption has no issues when it's being launched form the command line (e.g.: ros2 launch whatever_package whatever.launch.py).

Im running this from a really simple utility script (ld is the LaunchDescription obj). The code is the following:

from launch import LaunchService, LaunchDescription
from multiprocessing import Process

def start_launch_servide_process(ld):
    ls = LaunchService()
    ls.include_launch_description(ld)
    p = Process(target=ls.run)
    p.start()

What I want to achieve is that the LaunchService runner works exactly as the ros2 launch command. Any advice on how should I approach this? Thanks!

UPDATE

Im getting the error in the hros_cognition_mara_components node. Im not opening an issue in the main repo since the node works fine using the conventional startup process. This node is in charge of providing an observation for the reinforcement learning algorithms, so after it breaks, I cant receive any information. (Paths are okay, and working fine with ros2 launch)

[ERROR] [launch]: process[hros_cognition_mara_components-4] process has died [pid 5615, exit code -11, cmd '/home/nestor/ros2_mara_ws/install/lib/hros_cognition_mara_components/hros_cognition_mara_components -motors /home/nestor/ros2_mara_ws/install/share/hros_cognition_mara_components/link_order.yaml'].
edit retag flag offensive close merge delete

Comments

First, I would not recommend running LaunchService in a thread or via multiprocess. Instead I'd recommend running the LaunchService in the main thread to avoid issues with signal handling, and then run your code in a thread.

William gravatar image William  ( 2018-12-20 13:30:46 -0500 )edit

Also, you haven't described really what your issue is. You mention it doesn't behave as you like and that ros2 launch works as you want, but you haven't said what exactly is wrong when you use your script.

William gravatar image William  ( 2018-12-20 13:31:27 -0500 )edit

Thanks for your reply William,

I am creating a new version of gym-gazebo that will use ROS2, info. I will update the main comment in a sec, posting more specific content.

nzlz gravatar image nzlz  ( 2018-12-21 02:24:20 -0500 )edit