Skip to content

Commit f23b71a

Browse files
committed
Fix memory leak of kernel Popen 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 the Popen object stored in the kernel manager in `self.kernel`. The issue is that in normal circumstances, when a kernel's termination is successful via the ZMQ messaging, the process is never waited for (which, in this case, is probably unnecessary but advised) nor is the member variable set to None. In the failing case, where the message-based shutdown does not terminate the kernel process, the `_kill_kernel()` method is used, which performs the `wait()` and _nullifies_ the kernel member. This change ensures that sequence occurs in normal situations as well.
1 parent 4bfb5c4 commit f23b71a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

jupyter_client/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ def finish_shutdown(self, waittime=None, pollinterval=0.1):
272272
if self.is_alive():
273273
time.sleep(pollinterval)
274274
else:
275+
# If there's still a proc, wait and clear
276+
if self.has_kernel:
277+
self.kernel.wait()
278+
self.kernel = None
275279
break
276280
else:
277281
# OK, we've waited long enough.

0 commit comments

Comments
 (0)