博客
关于我
异步多线程处理
阅读量:428 次
发布时间:2019-03-06

本文共 1408 字,大约阅读时间需要 4 分钟。

import asyncio,time,requestsimport threading, time, requestsurl = "http://www.jd.com"total = 0suc = 0fail = 0exception = 0maxtime=0mintime=100gt3=0lt3=0class RequestThread(threading.Thread):    def __init__(self, thread_name):          threading.Thread.__init__(self)          self.test_count = 0    def run(self):        self.test_performace()    def test_performace(self):              global total            global suc            global fail            global exception            global gt3            global lt3            try:                  st = time.time()                  conn = requests.get(url)                res = conn.status_code                if res== 200:                    total+=1                    suc+=1                else:                    total+=1                    fail+=1                time_span = time.time()-st                  print ('%s:%f\n'%(self.name,time_span)  )                self.maxtime(time_span)                  self.mintime(time_span)                  if time_span>3:                    gt3+=1                else:                    lt3+=1            except Exception as e:                  print (e  )                total+=1                exception+=1    def maxtime(self,ts):              global maxtime            print (ts)            if ts>maxtime:                maxtime=ts    def mintime(self,ts):              global mintime            if ts

  

转载地址:http://bcjyz.baihongyu.com/

你可能感兴趣的文章
404 Note Found 团队会议纪要
查看>>
CentOS安装Docker-ce并配置国内镜像
查看>>
使用Redis作为Spring Security OAuth2的token存储
查看>>
【SOLVED】Linux使用sudo到出现输入密码提示延迟时间长
查看>>
springmvc转springboot过程中访问jsp报Whitelabel Error Page错误
查看>>
项目引入非配置的文件,打成war包后测试报错的可能原因
查看>>
Git学习笔记
查看>>
不需要爬虫也能轻松获取 unsplash 上的图片
查看>>
痞子衡嵌入式:语音处理工具pzh-speech诞生记(2)- 界面构建(wxFormBuilder3.8.0)
查看>>
痞子衡嵌入式:极易上手的可视化wxPython GUI构建工具(wxFormBuilder)
查看>>
痞子衡嵌入式:串口调试工具pzh-com诞生记(2)- 界面构建(wxFormBuilder3.8.0)
查看>>
elementUi源码解析(1)--项目结构篇
查看>>
Nmap扫描工具介绍
查看>>
算法笔记:递归、动态规划
查看>>
常用Windows 快捷键
查看>>
linux命令-压缩与打包
查看>>
ORACLE 11g 生产中高水位线(HWM)处理
查看>>
centos 6.x 编译安装 pgsql 9.6
查看>>
weblogic 服务器部署SSL证书
查看>>
Oracle Orion tool check io(ORACLE Orion 工具查看以及校验IO)
查看>>