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实现飞机大战游戏

飞机大战(Python)代码分为两个python文件,工具类和主类,需要安装pygame模块,能完美运行(网上好多不完整的,调试得心累。实现出来,成就感还是满满的),如图所示: 完整代...

Python pandas DataFrame操作的实现代码

1. 从字典创建Dataframe >>> import pandas as pd >>> dict1 = {'col1':[1,2,5,7],'...

Python将string转换到float的实例方法

Python将string转换到float的实例方法

Python 如何转换string到float?简单几步,让你轻松解决。 打开软件,新建python项目,如图所示 右键菜单中创建.py文件,如图所示 步骤中文件输入代码如下...

Python cookbook(数据结构与算法)根据字段将记录分组操作示例

本文实例讲述了Python根据字段将记录分组操作。分享给大家供大家参考,具体如下: 问题:想根据字典或者对象实例的某个特定的字典(比如日期)来分组迭代数据 解决方案:itertools....

python 添加用户设置密码并发邮件给root用户

#!/usr/bin/env python #coding: utf8 import os import sys import mkpasswd //这是之前写的,直接调用 impo...