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

Periodic long pauses between rospy.Timer callback calls [closed]

asked 2014-03-21 13:58:23 -0500

Jim Rothrock gravatar image

updated 2016-10-24 09:02:59 -0500

ngrennan gravatar image

I have a Python node that contains a class similar to this:

class Test(object):
    def __init__(self):
        self._timer = rospy.Timer(1 / 30.0, self._timer_cb)

    def do_stuff(self):
        while not rospy.is_shutdown():

    def _timer_cb(self, not_used):

At the end of the node, I do this:

test = Test()

I would expect _timer_cb() to print "_timer_cb()" roughly 30 times per second, while do_other_stuff() (which takes a few seconds to return) would run concurrently. My understanding is that each rospy.Timer object has its own thread. However, what's happening is that _timer_cb() is not called for a period of several seconds (roughly the length of time do_other_stuff() takes to execute), then it is called at a high frequency (as expected), then there is another multi-second pause. This behavior then repeats. Why is this happening? I am running ROS Hydro on Ubuntu 12.04 LTS. Gazebo 1.9.5 is generating the simulation time.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Jim Rothrock
close date 2015-08-24 17:58:18.321583

1 Answer

Sort by ยป oldest newest most voted

answered 2014-03-31 09:01:10 -0500

Jim Rothrock gravatar image

The problem seems to be that do_other_stuff() calls moveit_commander.RobotCommander methods to move the robot's arm. The RobotCommander methods are wrappers around C++ functions. Apparently, the functions do not release the Python interpreter's global interpreter lock, so the interpreter cannot switch threads during a function call. Therefore, _timer_cb() is never called while the arm is moving. I worked around this issue by putting do_stuff() and _timer_cb() in separate nodes.

edit flag offensive delete link more

Question Tools



Asked: 2014-03-21 13:58:23 -0500

Seen: 493 times

Last updated: Mar 31 '14