Ros node does not shutdown clean
I have the following code running. However when I shutdown the node, the computer always escalates to SIGKILL which takes a long time. This seems to be coming from the loop and reading out the files. If I just print a random message and skip the loop it works. Where is the error and how could I handle it? Here is the code:
#!/usr/bin/env python2
import cv2
import glob
import os
import rospy
from sensor_msgs.msg import Image
if __name__ == "__main__":
rospy.init_node('Publisher', anonymous=True)
hz = rospy.get_param("~rate", 3)
rate = rospy.Rate(hz)
ImgRaw = rospy.Publisher('/camera_topic', Image, queue_size=10)
img_files = "/image_folder/*.jpg"
sort_images = sorted(glob.glob(img_files))
while not rospy.is_shutdown():
for i, filename in enumerate(sort_images, 0):
print("Publish Image with Name: %s" %os.path.basename(filename))
rate.sleep()
How do you shut down the node? And what is it even doing? Probably the publishing part is missing, right?
I shut it down with ctrl+c. this is a mwe, where i deleted all the processing and publishing in the pipeline. to show that the loading of the images with glob in the loop somehow leads to this behavior.