import gevent
节省了多线程之间相互切换的时间消耗,优于多线程,常和多进程结合使用
eg:
import gevent
from gevent import monkey
monkey.patch_socket()#补丁
def work(num):
for i in range(num):
time.sleep(0.5)
print('今天吃了{}个苹果'.format(num))
lis = [3, 4] * 4
def gev():
gev_lis = [gevent.spawn(work, i) for i in lis]
gevent.joinall(gev_lis)
gev()