第十二节 gevent多任务

import gevent
from gevent import monkey
import time

monkey.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)
])
上一篇:g2图表


下一篇:jzoj6366. 【NOIP2019模拟2019.9.25】化学(chem)