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

首頁 > 編程 > Python > 正文

Python實現的多線程http壓力測試代碼

2019-11-25 16:22:06
字體:
來源:轉載
供稿:網友

本文實例講述了Python實現的多線程http壓力測試代碼。分享給大家供大家參考,具體如下:

# 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()

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python URL操作技巧總結》、《Python Socket編程技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武隆县| 铁岭市| 新邵县| 金华市| 岚皋县| 满洲里市| 宿州市| 湖南省| 江阴市| 孙吴县| 东明县| 淄博市| 英吉沙县| 义乌市| 乌兰察布市| 阿合奇县| 柳河县| 合阳县| 酒泉市| 古蔺县| 新干县| 日土县| 贵阳市| 上高县| 瑞丽市| 古交市| 嘉荫县| 古丈县| 安宁市| 新乐市| 无极县| 康马县| 泰来县| 嘉定区| 怀仁县| 琼结县| 贺州市| 邢台县| 托克逊县| 明光市| 翼城县|