ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

if __name__ == '__main__': doesn't matter at here (in the second code), also you could run your code without it like here:

Second code:

.
.
.
# MAIN
try:
    process()
except rospy.ROSInterruptException:
    pass

i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':

More information.


The main difference between First code and Second code is that the Second code used the rospy.spin() method which is a built-in ROS loop that triggers the publisher and subscriber in another thread, so you wouldn't need to an inner while in your code like the First example.

Relevant Question.

if __name__ == '__main__': doesn't matter at here (in the second code), also you could run your code without it like here:

Second code:

.
.
.
# MAIN
try:
    process()
except rospy.ROSInterruptException:
    pass

i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':

More information.


The main difference between First code and Second code is that the Second First code used the rospy.spin() method which is a built-in ROS loop that triggers the publisher publisher and subscriber subscriber in another thread, so you wouldn't need to an inner while while in your code like the First Second example.

Relevant Question.