ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I was recently looking for solving the same issue and thought I would add my experience as this thread didn't have an answer that solved my problem.
The issue I was seeing was that rosbag would not clean exit, and thus write the .bag.active -> .bag file. Sending SIGINT, SIGKILL, etc.. in any order to the processes could not remedy the situation on my system.
Using rosnode I was able to kill the rosbag and have it cleanly exit. This would be more difficult when running multiple rosbag records at once (as you would need to find the rosnode id of each), however with only one running rosbag record, simply using 'rosnode list' to search for "/record_xxxx" and then executing "rosnode kill /record_xxxx" where xxx is the node id will cleanly exit the rosbag recording process.
def terminate_ros_node(s):
list_cmd = subprocess.Popen("rosnode list", shell=True, stdout=subprocess.PIPE)
list_output = list_cmd.stdout.read()
retcode = list_cmd.wait()
assert retcode == 0, "List command returned %d" % retcode
for str in list_output.split("\n"):
if (str.startswith(s)):
os.system("rosnode kill " + str)
terminate_ros_node("/record")