python Timer
来源:互联网 发布:微信js安全域名设置 编辑:程序博客网 时间:2024/06/10 12:16
http://mail.python.org/pipermail/tutor/2004-November/033333.html
实现定时器最简单的办法是就是循环中间嵌time.sleep(seconds), 这里我就不赘述了
下面介绍以threading模块来实现定时器的方法。
使用前先做一个简单试验:
import threading
def sayhello():
t = threading.Timer(5.0, sayhello)
t.start()
运行结果如下
>python hello.py
hello world
hello world
hello world
下面是定时器类的实现:
class Timer(threading.Thread):
class CountDownTimer(Timer):
class CountDownExec(CountDownTimer):