Aiohttp并发响应挂起

所有请求均正常运行,但在完成90%的任务后,响应将被挂起并超时。

在以下代码中,如果将n_requests更改为1000或10,问题仍然存在,并且似乎总是有10%的问题不会得到响应。

它似乎只能处理2个请求(n_requests = 2):

import asyncio
import aiohttp

n_requests = 100

async def make_request(session,req_n):
    url = f"https://tbit-web.de/exec/ximg.php?fid={req_n}"
    print(req_n)
    async with session.get(url) as resp:
        print(req_n,"finish")

async def main():
    async with aiohttp.ClientSession() as session:
        counternr = 0
        while counternr < 9999:
            await asyncio.gather(
                *[make_request(session,i) for i in range(counternr,counternr + n_requests)]
        )
            counternr= n_requests + counternr

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
liaozhongfa 回答:Aiohttp并发响应挂起

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3158090.html

大家都在问