Python實(shí)現(xiàn)的多線程http壓力測(cè)試代碼
本文實(shí)例講述了Python實(shí)現(xiàn)的多線程http壓力測(cè)試代碼。分享給大家供大家參考,具體如下:
# Python version 3.3
__author__ = 'Toil'
import sys, getopt
import threading
def httpGet(url, file):
import http.client
conn = http.client.HTTPConnection(url)
conn.request("GET", file)
r = conn.getresponse()
#print(r.getheaders())
while not r.closed:
r.read(200)
conn.close()
def Usage():
print('''
Options are:
-c concurrency Number of multiple requests to make
-u host The host
-f file File on web
Example: httpget.py -c 100 -u www.example.com -f /
''')
if __name__ == '__main__':
opts, args = getopt.getopt(sys.argv[1:], "hc:u:f:")
global u, c, f
for op, value in opts:
if op == '-c':
c = int(value)
elif op == '-u':
u = value
elif op == '-f':
f = value
elif op == '-h':
Usage()
sys.exit(0)
else:
sys.exit(0)
threads = []
times = c
print('Test for ', u, f)
print('waiting...')
for i in range(0, times):
t = threading.Thread(target=httpGet(u, f))
threads.append(t)
for i in range(0, times):
threads[i].start()
for i in range(0, times):
threads[i].join()
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python URL操作技巧總結(jié)》、《Python Socket編程技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門(mén)與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
解決python xlrd無(wú)法讀取excel文件的問(wèn)題
今天小編就為大家分享一篇解決python xlrd無(wú)法讀取excel文件的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
Django中日期時(shí)間型字段進(jìn)行年月日時(shí)分秒分組統(tǒng)計(jì)
這篇文章主要介紹了Django中日期時(shí)間型字段進(jìn)行年月日時(shí)分秒分組統(tǒng)計(jì),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
python中使用百度音樂(lè)搜索的api下載指定歌曲的lrc歌詞
這篇文章主要介紹了python中使用百度音樂(lè)搜索的api下載指定歌曲的lrc歌詞,同時(shí)也分析出了歌曲的下載地址,需要的朋友可以參考下2014-07-07
Pandas如何將Timestamp轉(zhuǎn)為datetime類型
這篇文章主要介紹了Pandas如何將Timestamp轉(zhuǎn)為datetime類型,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
Python matplotlib 畫(huà)圖窗口顯示到gui或者控制臺(tái)的實(shí)例
今天小編就為大家分享一篇Python matplotlib 畫(huà)圖窗口顯示到gui或者控制臺(tái)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
python實(shí)現(xiàn)數(shù)通設(shè)備端口監(jiān)控示例
這篇文章主要介紹了python實(shí)現(xiàn)數(shù)通設(shè)備端口監(jiān)控示例,需要的朋友可以參考下2014-04-04
Python代碼實(shí)現(xiàn)找到列表中的奇偶異常項(xiàng)
這篇文章主要介紹了Python代碼實(shí)現(xiàn)找到列表中的奇偶異常項(xiàng),文章內(nèi)容主要利用Python代碼實(shí)現(xiàn)了從輸入列表中尋找奇偶異常項(xiàng),需要的朋友可以參考一下2021-11-11

