python paho mqtt运行客户端x分钟(python paho mqtt run client for x minutes)
我想在指定的时间段内运行我的paho mqtt客户端,而不是永远。 实施它的正确方法是什么?
PS我想要一个阻塞调用而不是事件驱动的loop_start()/ stop()工具
谢谢!
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!
最满意答案
你必须使用事件循环,否则它将无法工作。
因此,最好的办法是实现自己的循环并跟踪时间。 例如
startTime = time.time() runTime = 5 * 60 while True: mqttc.loop() currentTime = time.time() if (currentTime - startTime) > runTime: break这应该持续5分钟
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: breakThis should run for 5 mins
更多推荐
发布评论