python实现多线程return_python实现多线程

importthreadingimporturllib3importjsonpathfrom requests importrequestfrom ABtest.guid importGetGuid#解决认证报错

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)classABTest:

defab_test_result(self, ab_name):

url= "http:xxx"headers= {"Content-Type": "application/json"}

ori_data ={"channel": "cl-abtest-api","apiVersion": "1.0","postData": {"testNames": ["zjctesti","zjctestu"],"deviceId": ""}

}

ori_data["postData"]["deviceId"] =GetGuid().get_guid()#print(ori_data)

response = request(method="post", url=url, headers=headers, json=ori_data, verify=False)

res=response.json()

group_name= jsonpath.jsonpath(res, "$..[?(@.name=='{}')].result".format(ab_name))[0]#print(group_name)

group_name2 = group_name["groupName"]#print(group_name2)

res_headers =response.headers

RequestId= res_headers["RequestId"]#print(RequestId)

returngroup_name2defcheck_ab_result(self, num, ab_name, index_0_name, index_1_name, index_2_name, index_3_name):

group_name_list=[]for i inrange(num):

group_name=self.ab_test_result(ab_name)

group_name_list.append(group_name)

group_name_list_length=len(group_name_list)print("group_name_list_length:{}".format(group_name_list_length))

index_0_length=group_name_list.count(index_0_name)

index_1_length=group_name_list.count(index_1_name)

index_2_length=group_name_list.count(index_2_name)

index_3_length=group_name_list.count(index_3_name)print(index_0_length, index_1_length, index_2_length, index_3_length)

percent_0= "{:.6f}".format(index_0_length /group_name_list_length)

percent_1= "{:.6f}".format(index_1_length /group_name_list_length)

percent_2= "{:.6f}".format(index_2_length /group_name_list_length)

percent_3= "{:.6f}".format(index_3_length /group_name_list_length)

result= "{}:{},{}:{},{}:{},{}:{}"\

.format(index_0_name, percent_0, index_1_name, percent_1, index_2_name, percent_2, index_3_name, percent_3)print(result)returnresultif __name__ == "__main__":

abtest=ABTest()#result = abtest.check_ab_result(5, "zjctestu", "11", "22", "", None)

t1 = threading.Thread(target=abtest.check_ab_result, args=(100, "zjctestu", "11", "22", "", None))

t2= threading.Thread(target=abtest.check_ab_result, args=(100, "zjctestu", "11", "22", "", None))

t1.start()

t2.start()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值