Python 官方文档:入门教程 => 点击学习
#coding=utf-8 import Httplib,urllib from time import ctime import threading import csv postJSON={ } #定义需要
#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()
--结束END--
本文标题: python实现多线程post方法进行压
本文链接: https://www.lsjlt.com/news/187552.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0