python 多线程对post请求服务器测试并发的方法

yipeiwu_com5年前服务器

如下所示:

# -*- coding: utf-8 -*-
import requests
import threading
import time
class postrequests():
 def __init__(self):
  self.url = '请求网址'
  self.files = {
 'unknown_image':open('刘诗诗.jpg','rb')
}
 def post(self):
  try:
   r = requests.post(self.url,files=self.files)
   print(r.text)
  except Exception as e:
   print(e)

def login():
 login = postrequests()
 return login.post()
# if __name__ == '__main__':
#  login()
try:
 i = 0
 # 开启线程数目
 tasks_number = 150
 print('测试启动')
 time1 = time.clock()
 while i < tasks_number:
  t = threading.Thread(target=login)
  t.start()
  i +=1
 time2 = time.clock()
 times = time2 - time1
 print(times/tasks_number)
except Exception as e:
 print(e)

以上这篇python 多线程对post请求服务器测试并发的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python Gunicorn服务器使用方法详解

python Gunicorn服务器使用方法详解

1. 简介 Gunicorn(Green Unicorn)是给Unix用的WSGI HTTP 服务器,它与不同的web框架是非常兼容的、易安装、轻、速度快。 2. 示例代码1...

Python获取服务器信息的最简单实现方法

本文实例讲述了Python获取服务器信息的最简单实现方法。分享给大家供大家参考。具体如下: 主要核心代码如下: sUrl = 'http://www.163.com' sock =...

Python实现获取域名所用服务器的真实IP

本来是要写个程序用的,没写完不写了,这一部分就贴出来吧 验证域名和IP class JianKong(): '''查询IDC信息,封ip和过白名单''' def __init...

php实现在服务器端调整图片大小的方法

本文实例讲述了php实现在服务器端调整图片大小的方法。分享给大家供大家参考。具体分析如下: 在服务器端完成图片大小的调整,会比在浏览器的处理有很多的好处。 本文介绍了PHP如何在服务器...

python实现通过代理服务器访问远程url的方法

本文实例讲述了python实现通过代理服务器访问远程url的方法。分享给大家供大家参考。具体如下: import urllib proxies = {'http' : 'http:/...