Skip to content

Commit 06e8167

Browse files
committed
Fix leak of IOLoopKernelManager object
After analyzing various leaked items when running either Notebook or Jupyter Kernel Gateway, one item that recurred across each kernel startup and shutdown sequence was an instance of IOLoopKernelManager. (Of course, when using JKG, this instance was KernelGatewayIOLoopKernelManager since it derives from the former.) The leak is caused by the circular references established in the `self._restarter` and `self.session.parent` members. This change breaks the circular reference when the restarter is stopped and during `cleanup()` of the kernel manager. Once the references are broken, the kernel manager instance can be garbage collected.
1 parent 4bfb5c4 commit 06e8167

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

jupyter_client/ioloop/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def stop_restarter(self):
5454
if self.autorestart:
5555
if self._restarter is not None:
5656
self._restarter.stop()
57+
self._restarter = None
5758

5859
connect_shell = as_zmqstream(KernelManager.connect_shell)
5960
connect_iopub = as_zmqstream(KernelManager.connect_iopub)

jupyter_client/manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def cleanup(self, connection_file=True):
286286

287287
self.cleanup_ipc_files()
288288
self._close_control_socket()
289+
self.session.parent = None
289290

290291
def shutdown_kernel(self, now=False, restart=False):
291292
"""Attempts to stop the kernel process cleanly.

0 commit comments

Comments
 (0)