Ask Your Question

Revision history [back]

Well, after learning more I understand:

1 - The codes get into the while not rospy.shutdown() or rospy.spin(). When I asked, I thought the loop was into all the code (starting from import all over again).

2 - It is not necessary.

3 - while not rospy.shutdown() give more control if your node do complex tasks and rospy.spin() is to just keep that node alive in the thread (used for more simple ones, where you only have a simple tasks as be a service or a subscriber only). if __name__ == '__main__' it is a good practice in python only, nothing related to ROS.

4 - following this question basically rospy.spin() is a while not rospy.shutdown(), so when I asked my code get bugged most because I did such thing as:

while not rospy.shutdown():
    ....
    rospy.spin()

So this is basically wrong (in my POV), because is equally to:

while not rospy.shutdown():
    ....
    while not rospy.shutdown():