python 线程事件

与进程的事件相似

# 事件,模拟连接数据库
import time
from threading import Event, Thread


def wait(e):
    while 1:
        e.wait(1)
        if e.is_set():
            print('等待成功')
            break
        else:
            print('失败')


def check(e):
    time.sleep(2)
    e.set()


e = Event()
Thread(target=check, args=(e, )).start()
Thread(target=wait, args=(e, )).start()
原文地址:https://www.cnblogs.com/wt7018/p/11069192.html