python使用tomorrow实现多线程的例子

yipeiwu_com6年前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使用tomorrow实现多线程的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python编程实现随机生成多个椭圆实例代码

python编程实现随机生成多个椭圆实例代码

椭圆演示: 代码示例: import matplotlib.pyplot as plt import numpy as np from matplotlib.patches imp...

python链接Oracle数据库的方法

本文实例讲述了python链接Oracle数据库的方法。分享给大家供大家参考。具体如下: 这里使用python链接Oracle数据库需要引用cx_Oracle库 #coding=UT...

Python实现的读取文件内容并写入其他文件操作示例

Python实现的读取文件内容并写入其他文件操作示例

本文实例讲述了Python实现的读取文件内容并写入其他文件操作。分享给大家供大家参考,具体如下: 文件目录结构,如图: read_file.py是工作文件,file_test.py是读取...

使用pycharm生成代码模板的实例

通过在File->setting->File and Code Templates设置模板代码,这样就可以在新建python文件的时候自动带上抬头。 # -*- codi...

浅谈python的输入输出,注释,基本数据类型

1.输入与输出 python中输入与输出函数为:print、input help() 帮助的使用:help() help(print) print(value, ..., sep=...