Why ClientSession in async context manager freeze until timeout approximately once in 3-4 runs?
When I await any coroutine from response inside async context manager everything works normal but if I try to do it outside (or return response) it freeze?
Here is minimal representation of code
from aiohttp import ClientSession
import asyncio
async def fetch():
url = ...
headers = {"User-Agent": ...}
parameters = [...]
async with ClientSession() as session:
session.headers.update(headers)
response = await session.post(url, data=parameters, ssl=False)
# await response.json() # <-- This line fix problem
return response
async def main():
r = await fetch()
print(await r.json())
asyncio.run(main())
Problem fixed by returning response inside async context manager but I want to know why this problem appears.
New contributor
Альберт Давыдов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.