python使用tomorrow实现多线程的例子
时间:2021-06-01 08:51:22|栏目:Python代码|点击: 次
如下所示:
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实现购物评论文本情感分析操作【基于中文文本挖掘库snownlp】
栏 目:Python代码
下一篇:详解利用django中间件django.middleware.csrf.CsrfViewMiddleware防止csrf攻击
本文地址:http://www.codeinn.net/misctech/132970.html






