Run roscore from python
Hello,
I am trying to automate the launch of multiple nodes with the roslaunch API. So far, I am able to do what I want, and my nodes are running perfectly. (I am also able to stop them).
Now, I noticed that the roslaunch API doesn't work if no roscore is running (in a terminal)..
So I am trying to start the roscore at the beginning of my script (before starting my nodes). What I tried so far (also described here) is:
import subprocess
roscore_process = subprocess.Popen('roscore')
However, I am unable to stop the roscore process with roscore_process.kill()
.
It seems that the roscore
program creates a parent process that spawns multiple children processes (i assume: rosmaster, parameter server, rosout...). This can also be seen with top
or htop
. Therefore calling roscore_process.kill()
only kills one of the children.
Do you have any idea on how to start and stop a roscore ?
Thank you