-
Notifications
You must be signed in to change notification settings - Fork 298
Open
Labels
Description
KernelManager and KernelClient have nontrivial amounts of resources (usually sockets, but sometimes also dedicated event loops) to cleanup. #1076 had some issues that were caused by lots and lots of leftover unclosed zmq contexts, sockets, and event loops. This is understandable, because we don't actually have easy APIs for cleaning up resources used by these objects.
We should have:
- easy single cleanup method on both KernelManager and KernelClient that cleanup everything:
- sockets
- context, if created
- event loop, if created, for blocking implementations
- context manager methods that make it easier to ensure these things are cleaned up, even on exception
I suggest calling these cleanup methods .close()
, just like most open-resource-having objects.
we have some cleanup in __del__
, but relying on del is super unreliable and Python implementation-specific, and should really always throw a ResourceWarning that something wasn't closed properly, as is done with sockets, files, etc..