event信号控制线程

来源:互联网 发布:网络写手兼职 编辑:程序博客网 时间:2024/06/05 11:40
import threading
import time


event = threading.Event()

def func():
while True:
print "i love c an dlinux"
event.wait()

def test_func2():
while True:
print "test_func2........"
event.wait()

def test_func3():
while True:
print "test_func3....333333333333"
event.wait()

def test():
th2 = threading.Thread(target=func)
th3 = threading.Thread(target=test_func3)
th = threading.Thread(target=test_func2)
th3.start()
th2.start()
th.start()

time.sleep(2)
event.set()
time.sleep(2)
event.clear()

if __name__ == '__main__':
test()