博客
关于我
异步多线程处理
阅读量:437 次
发布时间: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/

你可能感兴趣的文章
net包之IPConn
查看>>
net发布的dll方法和类显示注释信息(字段说明信息)[图解]
查看>>
Net操作配置文件(Web.config|App.config)通用类
查看>>
NeurIPS(神经信息处理系统大会)-ChatGPT4o作答
查看>>
neuroph轻量级神经网络框架
查看>>
Neutron系列 : Neutron OVS OpenFlow 流表 和 L2 Population(7)
查看>>
NEW DATE()之参数传递
查看>>
New Relic——手机应用app开发达人的福利立即就到啦!
查看>>
new 一个button 然后dispose,最后这个button是null吗???
查看>>
next项目部署到服务器pm2进程守护
查看>>
nexus上传jar
查看>>
Nexus指南中的更新强调集成和透明度的重要性
查看>>
Nexus指南已经发布
查看>>
Nexus(1):Nexus的安装与配置
查看>>
NFinal学习笔记 02—NFinalBuild
查看>>
NFS
查看>>
NFS Server及Client配置与挂载详解
查看>>
NFS 服务配置篇
查看>>
NFS共享文件系统搭建
查看>>
nfs复习
查看>>