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

来源:互联网 发布:服务器安装centos系统 编辑:程序博客网 时间:2024/06/06 02:00
#coding=utf-8import httplib,urllibfrom 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():   #接口的urlrequrl =""   #连接服务器   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()

原创粉丝点击