python gevent异步
安装
pip install gevent
import gevent from gevent import monkey monkey.patch_all()#捕捉所有阻塞,不止接收gevent.sleep import time def f(s): print("hello-----%s"%s) time.sleep(3) def f2(s): time.sleep(3) print("hello------%s"%s) start=time.time() t=gevent.spawn(f,"f") t1=gevent.spawn(f2,"f2") gevent.joinall([t,t1]) end=time.time() print(end-start) hello-----f hello------f2 3.003866195678711 创建协程对象 gevent.spawn(函数,参数)
执行协程并阻塞等待执行完毕
gevent.joinall([协程对象],[timeout])
相关推荐
efeve 2020-09-14
jacktangj 2020-04-17
wyqwilliam 2020-02-10
shengge0 2019-12-26
wklken的笔记 2019-11-01
georgeandgeorge 2019-10-31
dashoumeixi 2020-07-20
SDUTACM 2020-05-03
zuiaiqun 2020-01-23
talkincode 2020-01-11
dashoumeixi 2019-12-22
zuiaiqun 2019-12-12
hamutailang 2019-11-03
chunjiekid 2019-07-01
talkincode 2019-06-30
solarLan 2019-06-28
mayflowers 2019-06-28