New message arrival while processing in callback function

asked 2020-04-02 11:06:14 -0500

cheesee61 gravatar image

Hello guys,

I am quite new to ROS so sorry for possibly dumb questions. I wanted to write a node with rospy, which subscribes to a topic and publishes to another topic at the same time (in the same script). The pseudocode looks like this:

Init node foo
Create publisher bar
Create Subscriber(foobar, mycallback)

do some time/cpu consuming stuff
publish to bar

I hope the snippet is understandable. The "mycallback()" function is invoked every time when a new message arrives at the "foobar" topic and the code inside the callback function is executed. But what happens when a new message arrives while processing some tasks? Will the iteration of the callback function just canceled or finished and the new message is stored in something like a buffer? How is that whole timing thing working?

If required, I will edit the code with a MWE

Thanks in advance

edit retag flag offensive close merge delete


The technical terminology here is "threading model" or "callback model". Related/previous questions: #q267960, #q220788 and #q9543.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-02 11:16:23 -0500 )edit