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

How does rospy.Timer behave if it triggers while the previous callback is still busy?

asked 2016-12-26 11:14:16 -0600

spmaniato gravatar image

I'm using a rospy.Timer (periodic, not one-shot) to handle a long-running process in a non-blocking way. I only want one instance of the process to be running at any one time. Therefore, I thought I would have to implement some sort of lock in order to prevent subsequent Timer callbacks from triggering new instances of the process.

However, it seems like I didn't have to! Subsequent callbacks are not called if the previous one is still working. Or are they added to a queue like subscriber callbacks? Either is a good thing in my use case, but where can I find out more about it? It's not mentioned in from what I can tell.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-12-26 12:30:10 -0600

NEngelhard gravatar image

You could have a look at the code:

The callback is directly executed (no thread) so if your function takes longer than your rate, it will be called as fast as possible (independent of your specified rate).

edit flag offensive delete link more


Thanks for the link! According to the source code, it looks like the callback should be getting called regardless of whether the previous one has returned. That's not what I observed though. Hmm. I'll take another look.

spmaniato gravatar image spmaniato  ( 2016-12-26 13:34:25 -0600 )edit

Why do you think so? The callback is called in line 223 in the main loop. So the execution waits there until your function finished.

NEngelhard gravatar image NEngelhard  ( 2016-12-26 15:22:27 -0600 )edit

Oh, now I get it! The entire Timer / thread is getting blocked by the call to the long-running callback. Thanks again @NEngelhard :-)

spmaniato gravatar image spmaniato  ( 2016-12-26 15:43:29 -0600 )edit

Question Tools

1 follower


Asked: 2016-12-26 11:14:16 -0600

Seen: 1,264 times

Last updated: Dec 26 '16