是threading.Event线程安全吗?

时间:2014-02-03 12:00:57

标签: python multithreading

是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__)

0 个答案:

没有答案