gpt4 book ai didi

python - 运行时钟和触发

转载 作者:太空宇宙 更新时间:2023-11-03 13:53:34 26 4
gpt4 key购买 nike

不断运行一个时钟并每 5 秒触发一次其他功能。

请告诉我怎么做。

非常感谢

最佳答案

>>> import sched, time
>>> s = sched.scheduler(time.time, time.sleep)
>>> def print_time():
... s.enter(5, 1, print_time, ())
... print "From print_time", time.time()
...
>>> s.enter(0, 1, print_time, ())
Event(time=1265846894.4069381, priority=1, action=<function print_time at 0xb7d1ab1c>, argument=())
>>> s.run()
From print_time 1265846894.41
From print_time 1265846899.41
From print_time 1265846904.42
From print_time 1265846909.42

关于python - 运行时钟和触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2241234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com