【发布时间】:2010-04-24 01:54:02
【问题描述】:
from threading import Timer
def hello():
print "hello, world"
t = Timer(30.0, hello)
t.start()
此代码只触发一次计时器。
如何让计时器永远运行?
谢谢,
更新
这是对的:
import time,sys
def hello():
while True:
print "Hello, Word!"
sys.stdout.flush()
time.sleep(2.0)
hello()
还有这个:
from threading import Timer
def hello():
print "hello, world"
sys.stdout.flush()
t = Timer(2.0, hello)
t.start()
t = Timer(2.0, hello)
t.start()
【问题讨论】:
标签: python multithreading timer