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

yipeiwu_com6年前服务器

如下所示:

# -*- 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设计】。

相关文章

php使用socket post数据到其它web服务器的方法

本文实例讲述了php使用socket post数据到其它web服务器的方法。分享给大家供大家参考。具体实现方法如下: function post_request($url, $dat...

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

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

使用python实现快速搭建简易的FTP服务器

使用python实现快速搭建简易的FTP服务器

上回说到,使用python搭建一个简易的web下载服务器,但是这个简易的服务器客户端不能够上传文件。这次来搭建一个简易的ftp服务器,来提供文件的下载和上传功能。 一、首先我们来安装提供...

浅析PHP程序防止ddos,dns,集群服务器攻击的解决办法

废话不多说,上代码复制代码 代码如下:<?php//查询禁止IP$ip =$_SERVER['REMOTE_ADDR'];$fileht=".htaccess2";if(!file...

python Gunicorn服务器使用方法详解

python Gunicorn服务器使用方法详解

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