多线程事件
Posted superniao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多线程事件相关的知识,希望对你有一定的参考价值。
import time import random from threading import Thread,Event def conn_db(e): count = 0 while count < 3: e.wait(1) if e.is_set(): print("连接数据库成功") break else: count += 1 print("第{}次连接数据库失败".format(count)) else: raise TimeoutError("数据库连接超时") def check_web(e): time.sleep(random.randint(1,3)) e.set() e = Event() t1 = Thread(target=conn_db,args=(e,)) t2 = Thread(target=check_web,args=(e,)) t2.start() t1.start()
以上是关于多线程事件的主要内容,如果未能解决你的问题,请参考以下文章
多线程代码中 QSerialPort 的 Qt 错误:QCoreApplication::sendEvent:“无法将事件发送到不同线程拥有的对象