Python speeds up program running problems
PHPz
PHPz 2017-05-18 10:45:07
0
3
652

Assumption:

def get(url):
    #这里是get请求
    return url

for i in urls:
    get(i)
#这里采用循环去调用请求
#这样速度好像比较慢,有什么方法可以
#当多个请求时,也可以快速完成程序

Thank you

PHPz
PHPz

学习是最好的投资!

reply all(3)
左手右手慢动作
>>> 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

漂亮男人

Several methods and can be used in combination

  1. coroutine

  2. multiprocess

  3. multithread

  4. celery worker

洪涛

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!