python螺纹计时器 - 每x秒激活函数
是否有任何简单的方法激活线程以每个x sec启动功能以显示一些数据?
def send_data():
data = "Message from client"
socket.sendall(data.encode())
write_thread = threading.Thread(target=send_data())
write_thread.start()
Is there any simple way to activate the thread to fire up the function every X sec, to display some data?
def send_data():
data = "Message from client"
socket.sendall(data.encode())
write_thread = threading.Thread(target=send_data())
write_thread.start()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试 iSchedule 模块 - 它为计划任何给定函数提供了非常简单的语法。
这是github页面的直接示例:
return_after
param inrun_loop()
是可选的超时。另外,如果您不熟悉,
@
语法是Python decorator 。You could try the ischedule module - it provides very straightforward syntax for scheduling any given function.
Here's an example straight from the GitHub page:
The
return_after
param inrun_loop()
is an optional timeout.Also, in case you're unfamiliar, the
@
syntax is a Python decorator.一个简单的方法就是这样:
A simple way would be this: