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