day04_06 单线程生成器的并行效果(协程)

__author__ = "Alex Li"

import time
def consumer(name):
    print("%s 准备吃包子啦!" %name)
    while True:
       baozi = yield

       print("包子[%s]来了,被[%s]吃了!" %(baozi,name))

'''
c = consumer("ChenRonghua")
c.__next__()
#c.__next__()


b1= "韭菜馅"
c.send(b1)  #yield传值
c.__next__()
'''

def producer(name):
    c = consumer('A')
    c2 = consumer('B')
    c.__next__()
    c2.__next__()
    print("老子开始准备做包子啦!")
    for i in range(10):
        time.sleep(1)
        print("做了1个包子,分两半!")
        c.send(i)
        c2.send(i)

producer("alex")
上一篇:Kafka客户端Producer与Consumer


下一篇:Spring Boot 集成 Dubbo 微服务