python使用tomorrow实现多线程
生活随笔
收集整理的這篇文章主要介紹了
python使用tomorrow实现多线程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import time,requestes
from tomorrow import threads
@threads(10)#使用裝飾器,這個函數異步執行
def download(url):return requests.get(url)
def main():start = time.time()urls = ['https://pypi.org/project/tomorrow/0.2.0/','https://www.cnblogs.com/pyld/p/4716744.html','http://www.xicidaili.com/nn/10','http://baidu.com','http://www.bubuko.com/infodetail-1028793.html?yyue=a21bo.50862.201879',]responses = [download(i) for i in urls]end = time.time()print("Time: %f seconds" % (end - start))
if __name__=="__main__":main()
不使用多線程:
使用多線程:
總結
以上是生活随笔為你收集整理的python使用tomorrow实现多线程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬取数据存入mysql
- 下一篇: windows 下安装 scrapy报错