Ask Your Question

If a subscriber callback hasn't finished before another message is recieved, is the next call queued?

asked 2020-07-06 18:47:42 -0500

cwillia109 gravatar image

updated 2020-07-06 18:48:02 -0500

In my Melodic Python node I am maintaining a list of messages from different sources with information to be used later. Lets say sensor 1 publishes some data that the node has to handle and update it's global list of sensor data. This may take a small time to handle, but there is another message on the same topic that was published very shortly after by sensor 2.

In this circumstance, would the callback finish it's work from when sensor 1 published before being called again to work with sensor 2, or would another thread open up, if available, and do the same work concurrently? Does this change between ROS versions?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-07-07 02:09:58 -0500

KenYN gravatar image

By default, the messages are queued, up to the number of messages you specify when you subscribe. Python, and ROS nodes in general, are single-threaded by default, so they will come one after the other. If you want to handle them in parallel, you need to explicitly kick off a separate thread when you get each message.

edit flag offensive delete link more


So the funny thing in ROS 1 is, that the threading model of roscpp and rospy are different.

roscpp is single-threaded by default.

rospy is essentially multi-threaded by default.

You'll want to update your answer.

Also: this question has many duplicates. @cwillia109: could I ask you to please search for terms like "threading model" and "rospy" (use Google, and append to your query). You should be able to find many, many Q&As about this topic.

gvdhoorn gravatar image gvdhoorn  ( 2020-07-07 02:40:15 -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


Asked: 2020-07-06 18:47:42 -0500

Seen: 174 times

Last updated: Jul 07 '20