标签:highlight lex 准备 简单的 传值 import 异步io __next__ 开始
异步IO的雏形:
简单的单线程下的并行效果
import time def consumer(name): print("%s 准备吃包子啦!"%name) while True: baozi = yield print("包子[%s]来了,被[%s]吃了!"%(baozi,name)) c = consumer("ChenRongHua") c.__next__()#调用只唤醒 yield # b1="韭菜馅" # # c.send(b1)#调用yield并传值 #c.__next__() def producer(name): c = consumer(‘A‘) c2 = consumer(‘B‘) c.__next__() c2.__next__() print("老子开始准备做包子啦!") for i in range(10): time.sleep(1) print("做了2个包子!") c.send(i) c2.send(i) producer("alex")
标签:highlight lex 准备 简单的 传值 import 异步io __next__ 开始
原文地址:http://www.cnblogs.com/xiaobai005/p/7966915.html