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

My understanding of callbacks in rospy in general is they're essentially handled sequentially during calls to Sleep and Spin, meaning they're implicitly threadsafe and I can modify the same data from multiple callbacks within a node without locks or other safeguards.

Unfortunately, no. Unlike roscpp, rospy creates a new thread for every Subscriber and Timer. In fact, rospy.spin() is just an infinite loop of half-second waits. As such, callbacks in rospy are not threadsafe. You should use locks in any rospy node where multiple callbacks of any kind might interact.