3.4 生产消费者模型


import time
def consumer(name):
print('我是[%s],我准备吃肠粉了' %name)
while True:
changfen=yield
time.sleep(1.5)
print('%s很高兴地把【%s】吃掉了' %(name,changfen))

def producer():
a1=consumer('Jackson')
a2=consumer('leoung')
a1.__next__()
a2.__next__()
for i in range(20):
time.sleep(1.5)
a1.send('肠粉%s'%i)
a2.send('肠粉%s'%i)
producer()
原文地址:https://www.cnblogs.com/jackson669/p/10473603.html