Python aiohttp ResourceWarning socket
Python aiohttp is a go-to library for asynchronous networking operations using “asyncio”. One of the things we use aiohttp for is to replace synchronous “requests” with asynchronous aiohttp operations, to run many concurrent downloads or uploads for example. However, this is a long-standing bug that causes spurious warnings on exiting the asyncio event loop (e.g. at the end of a script or function) like:
“aiohttp” ResourceWarning unclosed socket.socket
A workaround for this per the bug report above is to add a 250 millisecond delay just before closing the event loop, perhaps by:
await asyncio.sleep(0.25)
Aiohttp 4.0.0 is the current milestone for this to be fixed.