jupyter_client icon indicating copy to clipboard operation
jupyter_client copied to clipboard

ResourceWarning: unclosed eventloop

Open mdickinson opened this issue 5 years ago • 0 comments

I'm getting ResourceWarnings at garbage collection time in an application that uses the ThreadedKernelClient. The warnings resemble the following:

ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
  source=self)

These lines in the source appear to be where the event loop is being created, and set as the current asyncio event loop: https://github.com/jupyter/jupyter_client/blob/dc213de1b5cc7b5c28485ae799fecfef77589a85/jupyter_client/threaded.py#L178-L182

But then, in the immediately following line, we have: https://github.com/jupyter/jupyter_client/blob/dc213de1b5cc7b5c28485ae799fecfef77589a85/jupyter_client/threaded.py#L183

Here IOLoop is tornado's AsyncIOLoop, and that creates and sets its own new asyncio event loop. Creation is here: https://github.com/tornadoweb/tornado/blob/cc2cf078a39abec6f8d181f76a4e5ba9432364f3/tornado/platform/asyncio.py#L216

And then it's set as the current event loop for the thread here: https://github.com/tornadoweb/tornado/blob/cc2cf078a39abec6f8d181f76a4e5ba9432364f3/tornado/platform/asyncio.py#L131

The net effect is that the event loop originally created is never used, hence the ResourceWarning.

As far as I can tell, this is relatively harmless: the unused event loop is simply closed when there are no longer any references to it.

mdickinson avatar Oct 11 '19 08:10 mdickinson