Ask Your Question
1

Is a rospy subscriber callback queue processed serially?

asked 2017-10-28 08:20:44 -0500

highWaters gravatar image

Hello,

From https://answers.ros.org/question/9543... , I gathered that in fact such processing should happen serially. However. I have the following piece of code that behaves in a weird way. I have multiple nodes that are subscribed and publish to the same topic. Normally, on each call of the callback function, three lines should be printed, and it should look as:

[#msg x]

%

[&msg x], where x is incremented on each call (and is modified only in this callback function), and is declared somewhere else.

If I comment the lock as in the snippet, I'll get outputs like:

[#msg 1]

%

[&msg 2] ---> this should be 1!


[#msg 2]

%

[&msg 2]

So it seems that a new thread is spawned every-time. Has the rospy thread model changed?

rospy.Subscriber('/environment/fires_pb', Fires_Info, self.callback_fires_msg)
self.publish_fires = rospy.Publisher('/environment/fires_pb', Fires_Info, queue_size=200)

...

def callback_fires_msg(self, data):
    try:
        #self.myknowledge.lock_cb.acquire()
        self.simulation.callback_msg += 1
        msg = '\n[#msg ' + str(self.simulation.callback_msg) + ']  callback_fires_msg: \n' + str(np.array(self.simulation.fires))
        msg += '\n%callback_fires_msg, data: ' + str(np.array(data))
        rospy.loginfo(msg)
        for i,x in enumerate(data.id):
            for j, a in enumerate(self.simulation.fires[0]):
                if a == x:
                    self.simulation.fires[3][j] = data.intensity[i]
                    self.simulation.fires[4][j] = data.victims[i]
                    self.simulation.fires[5][j] = data.status[i]
                    self.simulation.fires[6][j] = 1
                    break
        msg = '\n[&msg ' + str(self.simulation.callback_msg) + ']  callback_fires_msg: \n' + str(np.array(self.simulation.fires[6]))
        rospy.loginfo(msg)
        #self.myknowledge.lock_cb.release()
    except:
        rospy.loginfo(
            "Unexpected error: " + str(sys.exc_info()) + ". Line nr: " + str(sys.exc_info()[2].tb_lineno))
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-03-06 11:50:09 -0500

As others have pointed out in the thread you refer to: Yes, the threading model is different. As far as I understand each callback gets its own thread per connection.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-10-28 08:20:44 -0500

Seen: 257 times

Last updated: Mar 06