python 并发编程 协程池
作者:互联网
协程池
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 '''
标签:mike,name,python,编程,play,协程池,gevent,time,eat 来源: https://www.cnblogs.com/mingerlcm/p/11254766.html