Skip to content

Commit

Permalink
Fix leak of IOLoopKernelManager object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevin-bates authored and davidbrochart committed Feb 21, 2020
1 parent e2da3b2 commit 7a8394d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions jupyter_client/ioloop/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def stop_restarter(self):
if self.autorestart:
if self._restarter is not None:
self._restarter.stop()
self._restarter = None

connect_shell = as_zmqstream(KernelManager.connect_shell)
connect_control = as_zmqstream(KernelManager.connect_control)
Expand Down
1 change: 1 addition & 0 deletions jupyter_client/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def cleanup(self, connection_file=True):

self.cleanup_ipc_files()
self._close_control_socket()
self.session.parent = None

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

0 comments on commit 7a8394d

Please sign in to comment.