协程池
from gevent.pool import Pool
from gevent import monkey;monkey.patch_all() import gevent from gevent.pool import Pool import time def eat(name): print("%s:eat 1" %name) time.sleep(3) print("%s:eat 2" %name) def play(name): print("%s:play 1" % name) time.sleep(4) print("%s:play 2" % name) pool = Pool(5) g1 = pool.spawn(eat,"mike") g2 = pool.spawn(play,"mike") start_time = time.time() gevent.joinall([g1,g2]) end_time = time.time() print(end_time-start_time) ''' mike:eat 1 mike:play 1 mike:eat 2 mike:play 2 4.031230688095093 '''