def cash_out(amount): while amount >0: amount-=1 yield 1 print(‘get again %s‘ %amount)atm=cash_out(5)print(type(atm))print(atm.next())print(234234)print(atm.next())
import timedef consumer(name): print("%s 准备吃包子啦!" %name) while 1: baozi = yield print("包子[%s]来了,被[%s]吃了!" %(baozi, name)) def producer(): c = consumer(‘A‘) c2 = consumer(‘B‘) c.next() c2.next() print("老子开始准备做包子啦!") for i in range(10): time.sleep(1) print("做了2个包子!") c.send(i) c2.send(i)producer()
时间: 2024-10-08 00:40:29