All the requests are working normally but after 90% of the tasks the responds get hung and timeout.
In the following code, if you change n_requests
to 1000 or 10 the problem is still there and it seems always to be 10% which wont get a response.
It only seems to work with 2 requests (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())