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()