与进程的事件相似

# 事件,模拟连接数据库
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()

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-04-24
猜你喜欢
  • 2021-07-20
  • 2022-12-23
  • 2022-02-17
  • 2022-01-18
  • 2022-12-23
  • 2021-07-30
  • 2021-08-03
相关资源
相似解决方案