前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python编写的多线程接口并发测试

python编写的多线程接口并发测试

作者头像
py3study
发布2020-01-08 18:44:37
1.4K0
发布2020-01-08 18:44:37
举报
文章被收录于专栏:python3python3
import requests
import json
import threading
import time
import uuid
class postrequests():
    def __init__(self):
        #产生UUID
        u = uuid.uuid1()
        #产生订单编号
        orderID = 'TEST' + u.hex
        self.url = 'http://123.57.210.36:8091/couponWeb/couponSX/comboCouponOrderFrozen'
        self.data = {"payOrderNo": orderID,"userId":"16500","activityId":"1103",
                     "couponIdNumMap":{"2580":2,"2581":2,"2582":2}}
        self.headers = {'content-type': 'application/json'}
        self.data = json.dumps(self.data)

    def post(self):
        try:
            r = requests.post(self.url, self.data, headers=self.headers)
            print(r.text)
        except Exception as e:
            print(e)

def kquan_bf():
    login = postrequests()
    return login.post()


try:
    i = 0
    # 开启线程数目
    tasks_number = 10
    print('测试启动')
    time1 = time.clock()
    while i < tasks_number:
        t = threading.Thread(target=kquan_bf)
        t.start()
        i +=1
    time2 = time.clock()
    times = time2 - time1
    print(times/tasks_number)
except Exception as e:
    print(e)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档