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

你可能感兴趣的文章
Nginx的端口修改问题
查看>>
nginx看这一篇文章就够了
查看>>
Nginx知识详解(理论+实战更易懂)
查看>>
Nginx简单介绍
查看>>
Nginx系列6之-rewirte功能使用案例总结
查看>>
nginx线程模型理解
查看>>
Nginx虚拟主机配置
查看>>
Nginx访问控制_登陆权限的控制(http_auth_basic_module)
查看>>
nginx访问控制配置
查看>>
Nginx负载均衡
查看>>
Nginx负载均衡和F5的区别---系统运维工作笔记001
查看>>
nginx负载均衡和反相代理的配置
查看>>
nginx负载均衡器处理session共享的几种方法(转)
查看>>
nginx负载均衡的5种策略
查看>>
nginx负载均衡的5种策略(转载)
查看>>
nginx负载均衡的五种算法
查看>>
Nginx负载均衡(upstream)
查看>>
nginx转发端口时与导致websocket不生效
查看>>
Nginx运维与实战(二)-Https配置
查看>>
Nginx部署_mysql代理_redis代理_phoenix代理_xxljob代理_websocket代理_Nacos代理_内网穿透代理_多系统转发---记录021_大数据工作笔记0181
查看>>