在下面的代码中,我尝试在没有为0.9s调用do_it()
时调用函数。但是,我不断创建新计时器并取消它。有没有办法只创建一个计时器线程并继续推迟它?
def expired():
print "Expired"
t = None
def do_it():
global t
print "tick", time.time()
if t:
t.cancel()
t = threading.Timer(0.9, expired)
t.start()
while True:
time.sleep(random.random())
do_it()