Python实现的多线程http压力测试代码
作者:toil 时间:2021-06-30 23:47:29
本文实例讲述了Python实现的多线程http压力测试代码。分享给大家供大家参考,具体如下:
# 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()
希望本文所述对大家Python程序设计有所帮助。
标签:Python,多线程,http
0
投稿
猜你喜欢
导航设计的流行趋势
2007-12-25 12:06:00
python设计微型小说网站(基于Django+Bootstrap框架)
2023-03-15 01:54:18
jQuery中文入门教程
2007-12-09 19:20:00
React redux 原理及使用详解
2023-07-14 15:41:58
Web2.0 体验式网站设计的41个关键点
2008-08-10 17:49:00
laravel的用户修改密码与绑定邮箱的详细操作
2023-06-17 09:55:06
随感:交互设计两三事
2009-05-18 13:54:00
python中的代码运行时间获取方式
2023-11-19 22:57:02
Python爬虫基础初探selenium
2023-07-26 17:40:50
SQL Server中Update的用法
2008-12-29 13:57:00
javascript 获取中文字符串长度
2009-10-18 12:06:00
PHP join()函数用法与实例讲解
2023-06-02 00:39:19
Javascript将string类型转换int类型
2023-09-17 00:05:37
Python实现调用另一个路径下py文件中的函数方法总结
2021-05-24 12:48:03
JavaScript大牛:Douglas Crockford
2009-03-31 12:06:00
oracle 常见等待事件及处理方法
2009-04-24 12:01:00
利用python在大量数据文件下删除某一行的例子
2023-08-24 09:15:22
Oracle性能究极优化
2010-07-30 13:02:00
如何使用ASP来读写注册表
2007-09-20 13:08:00
Python使用Selenium模块模拟浏览器抓取斗鱼直播间信息示例
2023-06-13 09:23:30