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!
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!
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