标签:int log 生成器 pre 准备 send style produce 包子
还可通过yield实现在单线程的情况下实现并发运算的效果
import time def consumer(name): print("%s 准备吃包子啦!" %name) while True: baozi = yield print("包子[%s]来了,被[%s]吃了!" %(baozi,name)) c = consumer("ChenRongHua") c.__next__() def producer(name): c = consumer(‘A‘) c2 = consumer(‘B‘) c.__next__() c2.__next__() print("我开始做包子啦!") for i in range(10): time.sleep(2) print("做了2个包子!") c.send(i) c2.send(i) producer("zhuziqin")
标签:int log 生成器 pre 准备 send style produce 包子
原文地址:http://www.cnblogs.com/Achin/p/7436184.html