标签:style hello span eve 异步 pip 阻塞 pat tar
安装
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])
标签:style hello span eve 异步 pip 阻塞 pat tar
原文地址:https://www.cnblogs.com/pfeiliu/p/12000309.html