#!/usr/bin/env python
#encoding: utf-8
import time
def consumer(name):
print ('%s 来吃包子了。。。' % (name))
while True:
baizi = yield #执行到这会暂停,直到调用next的方法,然后在从这里执行
print ("包子 [%s] 来了, 被 [%s] 吃了,,," % (baizi,name)) def producer():
c1 = consumer('lys') #生成迭代器
c2 = consumer('zhy')
c1.__next__() #迭代
c2.__next__()
for i in range(3):
print ('开始重新做包子了,,,')
time.sleep(1)
print ('做好了2个。来吃吧,,,')
c1.send(i) #发送给yied,接收参数
c2.send(i) producer()