国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

Python實(shí)現(xiàn)的多線(xiàn)程http壓力測(cè)試代碼

2020-02-23 04:20:19
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了Python實(shí)現(xiàn)的多線(xiàn)程http壓力測(cè)試代碼。分享給大家供大家參考,具體如下:

# Python version 3.3__author__ = 'Toil'import sys, getoptimport threadingdef 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)容感興趣的讀者可查看本站專(zhuān)題:《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ì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 庆城县| 湟源县| 江安县| 马公市| 霍林郭勒市| 航空| 青州市| 秦皇岛市| 韶关市| 青铜峡市| 杭州市| 德兴市| 安庆市| 厦门市| 靖江市| 斗六市| 安顺市| 吴堡县| 巴彦淖尔市| 小金县| 临洮县| 盐山县| 临沭县| 元阳县| 清镇市| 宝丰县| 海南省| 中宁县| 东明县| 安庆市| 博乐市| 扶风县| 宝兴县| 淮南市| 奉节县| 泽州县| 抚州市| 鄄城县| 永济市| 宣城市| 新田县|