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

相关文章

Python3 jupyter notebook 服务器搭建过程

1. jupyter notebook 安装 •创建 jupyter 目录 mkdir jupyter cd jupyter/ •创建独立的 Python3...

python服务器端收发请求的实现代码

最近学习了python的一些服务器端编程,记录在此。 发送get/post请求 # coding:utf-8 import httplib,urllib #加载模块 #urllib可...

Python中使用Flask、MongoDB搭建简易图片服务器

1、前期准备 通过 pip 或 easy_install 安装了 pymongo 之后, 就能通过 Python 调教 mongodb 了. 接着安装个 flask 用来当 web 服务...

PHP获取服务器端信息的方法

本文实例讲述了PHP获取服务器端信息的方法。分享给大家供大家参考。 具体实现方法如下: 复制代码 代码如下:/**  * 获取系统信息  *  * @...

使用浏览器访问python写的服务器程序

代码如下所示: import socket import re import multiprocessing def service_client(client_socket):...