当前位置: 首页 > 工具软件 > Tomorrow > 使用案例 >

Python3使用tomorrow异步

萧晓博
2023-12-01

Tomorrow

项目地址
作者madisonmay

 

import time
import requests
import sys
from tomorrow import threads
s=requests.Session()
jishu=0
@threads(10)
def download(url):
    global jishu
    for _ in range(5):
        try:
            jishu+=1
            aa=s.get(url)
            sys.stderr.write('%s  \r'%jishu)
            break
        except:
            pass
    return aa
urls = ['http://p.3.cn/prices/mgets?skuIds=J_1273600']*100
if __name__ == "__main__":
    start = time.time()
    responses = [download(url) for url in urls]
    html = [response.text for response in responses]
    end = time.time()
    print ("Time: %f seconds" % (end - start))

 

 



转载于:https://www.cnblogs.com/pyld/p/4716744.html

 类似资料: