paho.mqtt.python
paho.mqtt.python copied to clipboard
Publishing Message fails if Program exits directly after
Calling client.publish(topic, payload, qos=0) results in the message being handled as sent (client.on_publish function is executed) But if the python script ends after the publish call, the message does not get sent. Adding a time.sleep(1) after client.publish(...) consistently sends the message.
If you want to publish a message and ensure it's left the client before exiting then use single. The library queues publish requests so 'Publish` is likely to return before the message is actually sent.
Closing this for now - if you still have an issue then feel free to reopen but please provide a full example.