Assumption:
def get(url):
#这里是get请求
return url
for i in urls:
get(i)
#这里采用循环去调用请求
#这样速度好像比较慢,有什么方法可以
#当多个请求时,也可以快速完成程序
Thank you
ringa_lee2017-05-18 10:47:07
>>> from eventor import Eventor
>>> urllist = ["https://a.com", ....]
>>> def get(url):
# 网络IO耗时
return url
>>> e = Eventor(threadcount=3, taskunitcount=3, func=get, interval=1)
>>> result = e.run_with_tasklist(urllist)
>>> print(result)
Choose multi-core, multi-process or multi-thread according to your needs, coroutines speed up processing.
Move details: https://github.com/kute/eventor
We will add async await, celery worker, etc. in the future
漂亮男人2017-05-18 10:47:07
Several methods and can be used in combination
coroutine
multiprocess
multithread
celery worker
PHP中文网2017-05-18 10:47:07
The simplest modification is to use multiprocessing.dummy to perform multi-threaded tasks. You can check it, set the number of threads, and then it can be used without much modification to the program.