-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
roscpp: method getNumSubscribers() returns wrong number of subscribers? #1122
Comments
I believe this is by design— |
Thanks for your response. @mikepurvis Just as you said, if
why not name the method as After doing a experiment, I found that Well, then, what API should I call to get the number of subscribers?
|
Unfortunately, the ROS master doesn't (can't) know how many times a node (or nodelet manager) has subscribed to a topic, because it has no introspection into the node or nodelet manager. In order to do this, every node would have to do some kind of bookkeeping and report back to the master the number of callbacks it has attached to each subscriber. |
The name of this function has been chosen a long time ago. Changing it now would imply updating a lot of existing code. Instead the documentation should clarify the semantic of the function. If you think the documentation or docblock should be improved please propose a change to either of them. Ideally in an anonymous publish / subscribe system you shouldn't rely on the exact number of subscribers anyway. The provided number is mostly useful to determine if there are any subscriber or if not your code might be able to skip some computations to save resources. |
So greatful to receive your answers, really thank you all you guys! I would like to help change the documentation or docblock to help more people who encounter this problem like me. |
Late to the party but this issue still persists! And I'm using ros::TopicManager. The method is the same. Only it takes the name of the topic as a parameter. When I run my node and do a "rostopic info [name of topic]", I can see the subscribers clearly connected. But the method just returns 0! Any alternative method I can use? |
@abhijit-hota There are several unit tests in place which ensure that |
I'm having a similar problem as @abhijit-hota: The debug output of
Which is printed here. Doing a Doing a It's worth noting that the server node actually serves multiple actions that the same client node connects to. After the first EnvironmentI am running this on ROS melodic. Both server and client are C++ nodes. I have never seen this issue when running the nodes outside of Docker. |
I think I found out what was causing the issue for me. The issue was that my Docker containers had a much higher I found the solution thanks to ros/actionlib#93 (comment). I'm guessing something like this is happening moby/moby#38814:
|
Hi, everyone
We noticed that method getNumSubscribers() returns 1 when there are two subscribers in one procedure listening to the same topic. The following are the code and the running result:
this is the publisher node, which publishing message on the
test_topic
topic:and this is the subscriber node, two subscribers in one procedure listening to the same
test_topic
topic:this is the result of running the publisher and the subscriber:
as you can see, method getNumSubscribers() returns 1, though the two subscribers' callback function all get called when a new message has arrived on the
test_topic
topic.what confuses me is that the two callback functions all get called means that the two functions has been registered, but why the method getNumSubscribers() only think there is 1 subscriber. I think it should return 2 as there are two callback function waiting for the message.
So can anybody tell me how method getNumSubscribers() count the number of subscribers in such case?
ps: if the two subscribers are in two procedures, of course method getNumSubscribers() returns 2.
The text was updated successfully, but these errors were encountered: