摘要:
# def consumer():# while True:# x=yield# print('***',x)## c = consumer()# next(c) #执行代码到yield停止# c.send(1) #发送1给生成器,执行x=1,然后print x的值# # def consumer( 阅读全文
摘要:
'''concurrent.futures 模块提供了高度封装的异步调用接口ThreadPoolExecutor :线程池,提供异步调用ProcessPoolExecutor:进程池,提供异步调用。基本方法:submit(fn,*args,**kargs) 异步提交任务map(func,*itera 阅读全文
摘要:
from threading import Thread,Conditiondef func(conn,i): con.acquire() con.wait() print('在第%s个循环里'%i) con.release()con =Condition()for i in range(10): 阅读全文
摘要:
import timeimport randomfrom threading import Thread,Eventdef connect_db(e): count = 0 while count<3: e.wait(1) #状态为false的时候,我只等待1s就结束 if e.is_set() = 阅读全文