84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
Annahme:
def get(url): #这里是get请求 return url for i in urls: get(i) #这里采用循环去调用请求 #这样速度好像比较慢,有什么方法可以 #当多个请求时,也可以快速完成程序
Danke
学习是最好的投资!
>>> 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)
自己根据需求选择 多核多进程,还是多线程,协程加快处理。
详情移步:https://github.com/kute/eventor
后续再 加进 async await,celery worker等
几个方法,并且可以结合使用
coroutine
multiprocess
multithread
celery worker
最简单的改造就是用multiprocessing.dummy 执行多线程任务,可以查一下,设置好线程数量,然后对程序不需要太大改造,大体就能用。
自己根据需求选择 多核多进程,还是多线程,协程加快处理。
详情移步:https://github.com/kute/eventor
后续再 加进 async await,celery worker等
几个方法,并且可以结合使用
coroutine
multiprocess
multithread
celery worker
最简单的改造就是用multiprocessing.dummy 执行多线程任务,可以查一下,设置好线程数量,然后对程序不需要太大改造,大体就能用。