标签:rand spl 事件 code 技术分享 bre close and class
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()
标签:rand spl 事件 code 技术分享 bre close and class
原文地址:https://www.cnblogs.com/superniao/p/10126871.html