python 多線程對post請求服務器測試并發(fā)的方法
更新時間:2019年06月13日 08:39:55 作者:taojijisky
今天小編就為大家分享一篇python 多線程對post請求服務器測試并發(fā)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
如下所示:
# -*- 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
# 開啟線程數(shù)目
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請求服務器測試并發(fā)的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Python3連接MySQL(pymysql)模擬轉賬實現(xiàn)代碼
這篇文章主要介紹了Python3連接MySQL(pymysql)模擬轉賬實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-05-05
如何用tempfile庫創(chuàng)建python進程中的臨時文件
這篇文章主要介紹了如何用tempfile庫創(chuàng)建python進程中的臨時文件,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2021-01-01
Python打包模塊wheel的使用方法與將python包發(fā)布到PyPI的方法詳解
這篇文章主要介紹了Python打包模塊wheel的使用方法與將python包發(fā)布到PyPI的方法詳解,需要的朋友可以參考下2020-02-02

