是threading.Event线程安全吗?我可以通过拨打Class.event.wait()
安全地访问活动吗?
示例代码,
import threading
import time
class Worker(threading.Thread):
def __init__(self):
super(Worker, self).__init__()
self.startup_event = threading.Event()
def run(self):
time.sleep(4)
print('Hello World')
self.startup_event.set()
w = Worker()
w.start()
w.startup_event.wait()
print('%s started' % w.__class__.__name__)