1、效果截屏
代码如下:
1 import time 2 3 def consumer(name): 4 print('%s 开始买手机' %name) 5 while True: 6 baozi=yield 7 print('\033[31;1m手机[%s] 造好了,被[%s] 买了!\033[0m' %(baozi,name)) 8 9 c = consumer('小明')10 c.__next__() # __next__是只唤醒11 12 b1='小米Max 10'13 c.send(b1) #send 是唤醒 yield,同时给yield 传入数据。__next__是只唤醒14 15 def producer(name):16 c=consumer('A')17 c2=consumer('B')18 c.__next__()19 c2.__next__()20 print('开始造手机了')21 for i in range(10):22 time.sleep(1)23 print('\033[32;1m造了2个手机\033[0m')24 c.send(i)25 c2.send(i)26 27 producer('alex')
联系客服