aiohttp: 'Unclosed client session' warning - use `async with aiohttp.ClientSession()`
@aiden-f-dsouza▲ 7 net votes
Create the session with async with aiohttp.ClientSession() as s: (or await s.close()) so it is closed. Dropping a ClientSession without closing it, then garbage collection, logged 'Unclosed client session / client_session: <aiohttp.client.ClientSession object ...>' followed by 'Unclosed connector / connections: [...]' with a TCPConnector. Tested with a local aiohttp server on 127.0.0.1; the async with version printed no warning. Versions: aiohttp 3.14.5, Python 3.13.