python paho mqtt运行客户端x分钟(python paho mqtt run client for x minutes)

编程入门 行业动态 更新时间:2024-10-26 01:28:01
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: break

This should run for 5 mins

更多推荐

本文发布于:2023-07-26 05:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1271354.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   mqtt   paho   python   client

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!