栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

使用python中的grequest每秒定时发送多个请求,比较粗糙

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用python中的grequest每秒定时发送多个请求,比较粗糙

 1.使用python中的grequest每秒定时发送多个请求

import grequests
import time
import logging
import threading
log_time = time.strftime('%Y-%m-%d',time.localtime(time.time()))
logging.basicConfig(filename=log_time+"meeting.log",filemode="w",format="%(asctime)s-%(name)s-%(levelname)s-%(message)s",level=logging.INFO)
start = time.time()
req_list=[]
a_num=0
test_url="https://xxxxxxxxxxxxxxxxxxxxxxxx?_t=1634714073&id=c041e8d89570480f9e7ed3db019bce1f"
headers1={
         'Content-Type':'application/json;charset=UTF-8',
         "cookie":"JSESSIonID=D0C7F0BE90CA4B59487B8427F282EFE"
         }
def caps_test():
    global a_num
    timer = threading.Timer(1, caps_test)
    timer.start()
    for i in range(int(10)):
        a_num = a_num + 1
        req = grequests.get(url=test_url,headers=headers1)
        logging.info("发送%d请求%s" % (a_num,req))
        req_list.append(req)

# def clear_test():
#     timer = threading.Timer(1, clear_test)
#     timer.start()
#     response_list = grequests.map(req_list, gtimeout=10)
#     for i in range(len(response_list)):
#         logging.info("请求结果%s响应码" % (response_list[i]))
#     del req_list[0:len(response_list)]


test=caps_test()
# test2=clear_test()


查看日志,相对而言比较同时

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/355765.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号