Ask Your Question
1

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

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

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 http://wiki.ros.org/rospy/Overview/Ti... from what I can tell.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

NEngelhard gravatar image

You could have a look at the code: timer.py

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

Comments

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 imagespmaniato ( 2016-12-26 13:34:25 -0500 )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 imageNEngelhard ( 2016-12-26 15:22:27 -0500 )edit
1

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 imagespmaniato ( 2016-12-26 15:43:29 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 299 times

Last updated: Dec 26 '16