zoukankan      html  css  js  c++  java
  • 线程练习

    # -*- coding: utf-8 -*-
    import json
    import threading
    import time
    import requests
    from openpyxl import load_workbook
    
    
    file ="data_xiancheng.xlsx"  #要执行的文件
    def run_test():
        wb = load_workbook("data_xiancheng.xlsx")#加载文件
        ws = wb.active
        for i in range(2,ws.max_row+1):
            testValue = "".join(str(ws["A"+str(i)].value).split())
            refValue = "".join(str(ws["B"+str(i)].value).split())
            url = "http://接口地址:端口号/antf/api/elasticSearch//compareFuzzyMatch/v1?testValue=" + testValue + "&refValue=" + refValue
            headers = {"Content-Type": "application/json"}
            req = requests.get(url=url, headers=headers)
            res = json.loads(req.content)
    
            ws["C" + str(i)].value = res['responseBody']['insSimilarity']
            ws["D" + str(i)].value = res['responseBody']['antfSimilarity']
            ws["E" + str(i)].value = res['responseBody']['diffSimilarity']
    
        wb.save("data_xiancheng.xlsx")  #保存回文件
    
    try:
        print('测试启动')
        start_time = time.time()
        t = threading.Thread(target=run_test)
        t.start()   #启动线程
        t.join()   #主线程等待子线程执行结束
        end_time = time.time()
        print("耗时:",end_time-start_time)
    except Exception as e:
        print(e)
    
    
    
    
    

      

  • 相关阅读:
    1029 旧键盘 (20 分)
    1028 人口普查 (20 分)
    1026 程序运行时间 (15 分
    1025 反转链表 (25 分
    1024 科学计数法 (20 分
    1023 组个最小数 (20 分)
    将命令的输出保存到文件
    使用与管理控制台历史
    度量命令执行时间
    检查最后运行命令的状态
  • 原文地址:https://www.cnblogs.com/bubutianshu/p/12886749.html
Copyright © 2011-2022 走看看