← Back to team overview

mqtt-users team mailing list archive

Re: Duration of mqttc.loop() (python library)

 

Hi Roger,
thanks as usual for your explanation, I'm testing this and it's now clear.

S

Roger Light ha scritto:
Hi Stefano,

I'm a bit confused by observing that the call to mqttc.loop() takes exactly
1sec to execute, is there any reason for this? What if I need to react more
often in a loop?
loop() has a timeout parameter which is by default 1 second. When you
call loop(), it makes a select() call to ask if there is any incoming
or (if applicable) outgoing network data to be processed. It will wait
at most the amount of time specified by the timeout. If you are only
sending data, then your call to publish() will attempt to write its
message without needing the loop() call. This means that when you come
to call loop(), there is no outgoing data and most probably no
incoming data, so the select() call will hit the timeout. If you test
over a long while you may see that occasionally the loop() call is
shorter when a ping is made for example.

In 0.15, the timeout parameter is an integer number of milliseconds.
Try set it to 100 for example. In 0.16 (the upcoming pure Python
version) it will be a float number of seconds.

I hope this help.

Cheers,

Roger


--
  Stefano Costa, R&D Manager
  M +39 335 6565749
  Skype stefanocosta.bluewind
  http://www.bluewind.it/stefanoco?code=11



References