Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Python MQTT client publish.single/multiple blocks indefinitely?

Sorry missed your reply since I'm signed up for digest emails. In reference to this:

> Hi Tony,

publish.single() and multiple() do use loop_forever() which will block
"forever", but they use callbacks to break out of this. The
_on_publish() callback calls disconnect() when all of the messages
have been sent, and this (should) cause it to drop out of the
loop_forever() call.

If that isn't working for you, can you describe something about your
setup? (OS, Python version, ...)



Here's my setup:

Broker server: mosquitto v1.3.1 running on an Ubuntu 14.04 LTS server image on Amazon EC2.  Broker is using the stock mosquitto config but with TLS enabled and a self-signed cert being used for TLS.

Client: paho-mqtt 0.9 client (installed with pip from ) running on a Raspberry Pi with Raspbian 'jessie' (Debian testing).

On another machine I subscribed to a topic using mosquitto_sub (just a simple 'hello/world' topic).  On the Rasbperry Pi I ran this simple script to test sending a message to the hello world topic:

import ssl
import paho.mqtt.publish as publish

tls = { 'ca_certs': '/etc/mosquitto/ca_certificates/mqtt_ca.crt',
'certfile': '/etc/mosquitto/certs/mqtt_client.crt',
'keyfile': '/etc/mosquitto/certs/mqtt_client.key',
'tls_version': ssl.PROTOCOL_TLSv1 }

payload='hello world', 

When run I can see the message getting sent to the topic--my subscribed machine prints out the 'hello world' message.  However the python script never finishes running and I have to stop it with ctrl-c.  When stopped it seems to be waiting in a select call (probably waiting for some network traffic to be received in loop_forever).

Is there some special server config that has to be enabled to send back a publish message that might be getting missed?  I'm not super familiar with the MQTT protocol but since this message is getting sent with the default qos level 0 there shouldn't be any acknowledgement of the send right?  Thanks for the help!


On Fri, May 16, 2014 at 2:56 PM, Tony DiCola <tony@xxxxxxxxxxxxxx> wrote:
Hey all, sorry if this is a known issue but is it by design that the publish.single or multiple functions are supposed to block indefinitely?  I noticed the source for them connects, sends messages, and then calls client.loop_forever() so execution never returns back to the caller.  How is a client application supposed to use these functions?

Back to the top