带有事件对象的Python线程
发布于 2021-01-29 17:48:06
我已经看到很多在类中使用Threads的Python脚本,其中许多使用threading.Event()
。例如:
class TimerClass(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run(self):
while not self.event.is_set():
print "something"
self.event.wait(120)
在while
循环中,为什么不设置条件就检查条件self.event
?
关注者
0
被浏览
42
1 个回答