from gevent import monkey;monkey.patch_all()
from gevent.queue import Queue #队列 gevent中的队列
import gevent
import random
#这个猴子补丁,all是所有能切换协程的地方都切换,包含了socket,所以一般都用all
qq = Queue(3)
def produceer():
while True:
item = random.randint(0,99)
qq.put(item)
print("生产了:", item)
def consumer():
while True:
item = qq.get()
print("消费了:",item)
p = gevent.spawn(produceer)
c = gevent.spawn(consumer)
gevent.joinall([p,c])
图例: