简单的携程程序
import time def consumer(name): print("%s准备吃包子了"%name) while True: baozi = yield print("[%s]包子来了,[%s]吃吧"% (baozi,name)) # c = consumer("Caicai") # c.__next__()###只能调用,不能传值 # c.send("韭菜")###通过send()向生成器中的yield传一个值进去 def produ(name): proper_1 = consumer("Caicai") proper_2 = consumer("CaiCai") proper_1.__next__() proper_2.__next__() print("准备好了吗") for i in range(10): time.sleep(2) print("%s:两个包子好了"%name) proper_1.send(i) proper_2.send(i) produ("DaDa")
以上内容作为课堂笔记,如有雷同,请联系于我