What is difference between rospy.spin() and while not rospy.is_shutdown()?

Hi @vasank1958,

Code 2 is not publishing continuously because it’s just “running out”; by the time the last line is executed, there’s nothing more happening, so the program ends, and forces ROS to shutdown.

Code 1, however, does not end because it has a while loop that keeps it alive unless ROS is shutting down.

Usually ROS does NOT shutdown unless you press CTRL + C or there’s an error, or the code itself stops executing (like in your case).

As for the difference you asked:

1 Like