eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.12k stars 722 forks source link

Error/status handling in publish.single method #807

Closed buhln closed 5 months ago

buhln commented 5 months ago

We are using the publish.single method for sending MQTT messages in a really low frequency and it works great as long the server is available. Unfortunatly we see no possibility at the moment to monitor the successfull sent of the message. Is there a possible solution for this?

If the server is not available we catch this by try/except...

Thanks in advance! nico

PierreF commented 5 months ago

That seems like the wanted behavior. If publish.single return (without exception) your message is published. If not not, it's not published. Having a function raise exception on error (like network error) is the right behavior IMO.

I'm not sure what behavior you are expecting. Do you want publish.single to retry connection by itself (e.g. can't fail, either return on success or hang - possibly forever) ?

buhln commented 5 months ago

Hi, Thank you for your answer.

I was looking for the best way to handle this. As I mention, we are catch errors at the moment by try/except. If this is the best way to do this for this function I am fine with it. Thanks!