DAY3 生成器学习

import time
def consumer(name):
    while True:
        print('老子%s准备吃包子啦!'%(name))
        baozi = yield
        print('老子%s吃了第%s个包子了' %(name,baozi))

def producer(name):
    print('你爹我%s准备做包子啦!' % name)
    a = consumer('xiaoming')
    b = consumer('zhangsan')
    a.__next__()
    b.__next__()
    for i in range(1,5):
        print('目前总共做了%s包子!' %(i*2))
        time.sleep(2)
        b.send(i)
        a.send(i)
producer('tianqiang')

 

posted on 2017-05-12 10:38  feel628  阅读(115)  评论(0)    收藏  举报

导航