0

I want to run my paho mqtt client for specified period of time and not forever. What is the right way to implement it?

P.S. I want a blocking call and not the event driven loop_start()/stop() facility

Thanks!

Priyank Mehta
  • 2,453
  • 2
  • 21
  • 32

1 Answers1

1

You have to use the event loop or it just won't work.

So your best bet is to implement your own loop and keep track of time. e.g.

startTime = time.time()
runTime = 5 * 60
while True:
  mqttc.loop()
  currentTime = time.time()
  if (currentTime - startTime) > runTime:
    break

This should run for 5 mins

hardillb
  • 54,545
  • 11
  • 67
  • 105