python-协程gevent的使用
import geventfrom gevent import monkeyimport timeimport random# 有耗时操作时需要monkey.patch_all() # 将程序中用到的耗时操作代码,换为 gevent 中自己实现的模块def work(name): for i in range(10): print(name, i) time.sleep(random.random())gevent.joinall([ gevent.spawn(work, ‘work1‘), gevent.spawn(work, ‘work2‘)])# 等价于‘‘‘g1 = gevent.spawn(work, ‘work1‘)g2 = gevent.spawn(work, ‘work2‘)g1.join()g2.join()‘‘‘
相关推荐
efeve 2020-09-14
jacktangj 2020-04-17
wyqwilliam 2020-02-10
zuiaiqun 2020-01-23
talkincode 2020-01-11
shengge0 2019-12-26
hamutailang 2019-11-03
georgeandgeorge 2019-10-31
dashoumeixi 2020-07-20
SDUTACM 2020-05-03
dashoumeixi 2019-12-22
zuiaiqun 2019-12-12
chunjiekid 2019-07-01
talkincode 2019-06-30
solarLan 2019-06-28
mayflowers 2019-06-28