异步多线程处理
发布日期:2021-05-09 04:19:53 浏览次数:11 分类:博客文章

本文共 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

  

上一篇:线程进程学习
下一篇:Python 接口测试(十)

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年03月22日 17时03分10秒