【发布时间】:2018-01-29 06:08:18
【问题描述】:
代码:
from threading import Timer, Event
from time import sleep
def hello(e):
print e
print 'Inside......'
while True:
if e.isSet():
print "hello_world"
break
if __name__ == '__main__':
e = Event()
t = Timer(1, hello(e,))
t.start()
print e.isSet()
sleep(2)
e.set()
print e.isSet()
输出:
[root@localhost ~]# python test_event.py
<threading._Event object at 0x7f440cbbc310>
Inside......
在上面的代码中,我试图从 python 中理解 Timer and, Event 对象。如果我运行上面的代码,Timer 会调用函数hello() 并且它会无限期地运行。主线程没有执行t.start() 旁边的行。我在这里想念什么?
谢谢。
【问题讨论】:
-
threading.Timer()的可能重复
标签: python multithreading events timer