python :生产者和消费者模型 即简单的协程
def consumer(name): print('%s开始准备吃包子了' %name) while True: baozi=yield print('[%s]包子来了,被[%s]吃了' %(baozi,name)) def product(name): print('%s开始做包子了' %name) c=consumer('张三') #生成器 c1=consumer('李四') c.__next__() c1.__next__() for i in range(10): print("做好了2个包子") c.send(i) c1.send(i) product('alex')