ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

I recommend you to use the subprocess module to solve this problem. e.g.:

#!/usr/bin/env python

import rospy
import subprocess 

child = subprocess.Popen(["roslaunch","ros_arduino_python","arduino.launch"])
#child.wait() #To block the parent process untill the child process finished.
print("parent process")

child.poll()
rospy.loginfo('The PID of child: %d',child.pid)
rospy.sleep(5)
child.kill()

#for more: https://docs.python.org/2/library/subprocess.html

I recommend you to use the subprocess module to solve this problem. e.g.:

#!/usr/bin/env python

import rospy
import subprocess 
subprocess
import signal

child = subprocess.Popen(["roslaunch","ros_arduino_python","arduino.launch"])
#child.wait() #To #You can use this line to block the parent process untill the child process finished.
print("parent process")
print(child.poll())
 child.poll()
rospy.loginfo('The PID of child: %d',child.pid)
rospy.sleep(5)
child.kill()
%d', child.pid)
print ("The PID of child:", child.pid)

rospy.sleep(15)

child.send_signal(signal.SIGINT) #You may also use .terminate() method
#child.terminate()

#for more: https://docs.python.org/2/library/subprocess.html