Python3使用tomorrow異步


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))

 

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM