Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A rospy subscriber callback thread locking question

I have a rospy node that has both a main loop and a subscriber callback that both need to modify the same global variable and I'm wondering if I have to use thread locking to prevent weirdness. The following snippet exhibits what I mean. Does the variable self.move_cmd.angular.z need locking in this situation?

def __init__():

    rospy.subscriber('roi', RegionOfInterest, self.roi_callback)

    while not rospy.is_shutdown():
        if not target_visible:
            self.move_cmd.angular.z = 0


def roi_callback(self, msg):
    if msg.width !=0 and msg.height != 0:
       self.move_cmd.angular.z = 0.1 * msg.x_offset