Sometimes when my raspy node is running (launched with rosrun) I can interrupt it with a control-c, and sometimes not. What's the best practice for making sure that my raspy nodes see a control-c and allow me to do a clean shutdown?
Follow-up
What about this case, where I think it all looks correct and nothing in the loop is long running, and yet I often have to do ^c many many times before it responds. Oddly shift ^c seems to interrupt better. I don't even know what shift ^c is!
rate = rospy.Rate(5)
count_log = 0
while not rospy.is_shutdown():
count_log += 1
if (count_log % 10 == 0):
print("\n#%s [%s] %s=%1.2f" % (count_log, self.state,
self.m.closest_dir, self.m.closest_dist))
if (self.m is None):
pass
elif (self.state == "find_wall"):
self.handle_find_wall()
elif (self.state == "follow_wall"):
self.handle_follow_wall()
elif (self.state == "emer_stop"):
self.handle_emer_stop()
rate.sleep()
Originally posted by pitosalas on ROS Answers with karma: 628 on 2018-08-01
Post score: 2
Original comments
Comment by jayess on 2018-08-01:
Are you checking rospy.is_shutdown()
during your loops? http://wiki.ros.org/rospy/Overview/Initialization%20and%20Shutdown#Testing_for_shutdown
Comment by pitosalas on 2018-08-01:
Yes, in some cases. But I was looking at sample code and I saw some examples that didn't do that. Also I found that even if I did rosy.is_shutdown() it seemed sometimes like the control-c didn't work. So I thought there might be a best practice for ensuring that I can always kill my nodes
Comment by gvdhoorn on 2019-02-16:
@pitosalas: @Geoff already answered the previous version of your question, and you accepted the answer. It's considered bad form to edit a question after there is an accepted answer. It would be better to post a new question as a follow-up (which I believe you already did: #q315792).