import geventfrom gevent import monkeyimport timemonkey.patch_all() # 将程序中用到的耗时模块操作的代码,换为gevent中自己实现的模块def f(n): for x in range(n): print(gevent.getcurrent(), x) time.sleep(0.5)# g1 = gevent.spawn(f, 5)# g2 = gevent.spawn(f, 5)# g3 = gevent.spawn(f, 5)# g1.join()# g2.join()# g3.join()gevent.joinall([ gevent.spawn(f, 5), gevent.spawn(f, 5), gevent.spawn(f, 5)])
来源:https://www.cnblogs.com/kogmaw/p/12575527.html