Errors running LaunchService unsing threading/multiprocessing.
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 hroscognitionmara_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'].
Asked by nzlz on 2018-12-20 11:30:54 UTC
Comments
First, I would not recommend running
LaunchService
in a thread or viamultiprocess.
Instead I'd recommend running theLaunchService
in the main thread to avoid issues with signal handling, and then run your code in a thread.Asked by William on 2018-12-20 14:30:46 UTC
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.Asked by William on 2018-12-20 14:31:27 UTC
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.
Asked by nzlz on 2018-12-21 03:24:20 UTC