生产者消费:
1 def consumer(name):
2 print(
"我是%s,我准备吃包子!" %
name)
3 while True:
4 baozi =
yield
5 print(
"%s 很开心的把【%s】吃掉了" %
(name,baozi))
6
7 def producer():
8 c = consumer(
"alex")
9 c1 = consumer(
"tom")
10 next(c)
11 next(c1)
12 for i
in range(10
):
13 if i / 2 ==
0:
14 c.send(
"包子%s" %
i)
15 else:
16 c1.send(
"包子%s" %
i)
17 producer()
转载于:https://www.cnblogs.com/Tang-Yuan/p/9804603.html
相关资源:JAVA上百实例源码以及开源项目
转载请注明原文地址: https://mac.8miu.com/read-74664.html