Call a function after a specified number of seconds:
t = Timer(30.0, f, args=None, kwargs=None)
t.start()
t.cancel() # stop the timer's action if it's still waiting
2.源码分析
classTimer(Thread):# 继承自Thread类"""Call a function after a specified number of seconds:
t = Timer(30.0, f, args=None, kwargs=None)
t.start()
t.cancel() # stop the timer's action if it's still waiting
"""def__init__(self, interval, function, args=None, kwargs=None):# 初始化的时候传参是延迟时间、调用的函数,函数的可变位置参数、函数的可变关键字参数
Thread.__init__(self)# 调用Thread类初始化配置实例
self.interval = interval # 在使用Thread类初始化配置实例之后再额外的增加interval属性
self.function = function # 同理再额外的增加function属性
self.args = args if args isnotNoneelse[