您的位置:首页 > 编程语言 > Python开发

python实现多线程post方法进行压测脚本模板

2017-07-21 00:00 811 查看
#coding=utf-8
import httplib,urllib
from time import ctime
import threading
import csv

postJson={
}
#定义需要进行发送的数据
params = urllib.urlencode(postJson);

#定义一些文件头
headers = {"Content-Type":"application/x-www-form-urlencoded",
"Connection":"Keep-Alive"
}

#创建请求函数
def Clean():

#接口的url
requrl =""
#连接服务器
conn = httplib.HTTPConnection("")
#发送请求
conn.request(method="POST",url=requrl,body=params,headers=headers)
#获取请求响应
response=conn.getresponse()
#打印请求状态
print response.status

#创建数组存放线程
threads=[]
#创建100个线程
for i in range(100):
#针对函数创建线程
t=threading.Thread(target=Clean,args=())
#把创建的线程加入线程组
threads.append(t)

print 'start:', ctime()
if __name__ == '__main__':
#启动线程
for i in threads:
i.start()
#keep thread
for i in threads:
i.join()

print 'end:', ctime()
#Url.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: