sniffio
sniffio copied to clipboard
Asyncio checks on py3.6 and older create a new event loop
While tracking down a ResourceWarning about an unclosed event loop, I discovered that asyncio.Task.get_current(), used by sniffio, calls asyncio.get_event_loop() which creates a new event loop. To avoid this, we should call asyncio._get_running_loop() to determine whether we have a running event loop in the thread. Whether we need to ensure that we're in a task too is another matter.