19.生产者消费者模型

import  time

def consumer(name):
    print('我是[%s],我准备开始吃包子了' %name)
    while True:
        baozi=yield
        time.sleep(1)
        print('%s 很开心的把【%s】吃掉了' %(name,baozi))

def producter():
    c1=consumer('raitorei')
    c2=consumer('ray')
    c1.__next__()
    c2.__next__()
    for i in range(10):
        time.sleep(1)
        c1.send('包子 %s' %i)
        c2.send('包子 %s' %i)
producter()
原文地址:https://www.cnblogs.com/raitorei/p/11953405.html