sniffio icon indicating copy to clipboard operation
sniffio copied to clipboard

Asyncio checks on py3.6 and older create a new event loop

Open agronholm opened this issue 5 years ago • 0 comments

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.

agronholm avatar Aug 08 '20 14:08 agronholm