Listener is not called (Python API)

5 posts / 0 new
Last post
Offline
Last seen: 10 months 1 week ago
Joined: 11/23/2021
Posts: 32
Listener is not called (Python API)

Hi@all,

I set up a simple publisher hello_world application with the Python API that sends hello_world samples to a hello_world subscriber application written in Micro C.
So far everything works finde and when I open Admin Console to have a look if both (participant and subscriber) are matched it doenst display any matching errors between the applications (matching is fine).

In the Python publisher application I have attached a Listener to the data wrter that listens for a matched subscription, see following code:

# create a data writer
writer_qos = dds.QosProvider.default.datawriter_qos_from_profile("Data_Library::Dw_QoS")
hw_data_writer = dds.DynamicData.DataWriter(publisher, hello_world_topic, writer_qos)
hw_data_writer.bind_listener(MyWriterListener(), dds.StatusMask.SUBSCRIPTION_MATCHED)

 

MyWriterListener():

class MyWriterListener(dds.DynamicData.NoOpDataWriterListener):
    def on_publication_matched_handler(self, writer, status):
        print("Matched occured\n")
        if status.current_count.change > 0:
            print("Matched a subscriber\n")
        if status.current_count.change < 0:
            print("Unmatched a subscriber\n")


However if I run the publisher and then start the subscriber there is no "Matched a subscriber" printout on the screen of the publsiher application side because the MyWriterListener() method is not going to be called.
Has anybody a idea why this isnt working? Did I miss something?

Thanks in advance!

Regards,

Marc

 

 

Marc.Chiesa's picture
Offline
Last seen: 2 years 2 months ago
Joined: 07/24/2017
Posts: 32

Hi Marc,

Two things I noticed:

  • Your status mask should include dds.StatusMask.PUBLICATION_MATCHED instead of SUBSCRIPTION_MATCHED
  • The name of your listener handler method should be on_publication_matched without the _handler at the end

Try updating with those changes and let me know if you still aren't getting any callbacks for this event.

Regards,

Marc

Offline
Last seen: 10 months 1 week ago
Joined: 11/23/2021
Posts: 32

Hi Marc,

Now its running, however if I close the subscriber application it doesn't entry the current_count_change < 0 if statement in my publisher application. It doesn't neither call the Listener.

So that the "Unmatched a subscriber" message doesnt appear.

class MyWriterListener(dds.DynamicData.NoOpDataWriterListener):
    def on_publication_matched(self, writer, status):
        print(status.current_count_change)
        if status.current_count_change > 0:
            print("Matched a subscriber\n")
        if status.current_count_change < 0:
            print("Unmatched a subscriber")

Any ideas?

Regards,

Marc

Marc.Chiesa's picture
Offline
Last seen: 2 years 2 months ago
Joined: 07/24/2017
Posts: 32

Hi Marc,

In this case it likely depends on how the subscribing application is being shut down. If it is a "graceful" termination and the DataReader is being explicitly deleted via API, you should get a callback as soon as the publishing application is notified by the subscribing app's participant. If it is an "ungraceful" app termination (e.g. ctrl-c) then the publishing application will not get a notification immediately and will have to wait for the subscribing application's participant liveliness to expire, which can take up to ~2 minutes with default QoS.

Regards,

Marc

Offline
Last seen: 10 months 1 week ago
Joined: 11/23/2021
Posts: 32

Hi Marc,

Thanks for your help!
Yes if I do a rough shut down of the application the "Unmatched a subscriber" message appears after 110 seconds.

Regards,

Marc