From 2d688f2071ce14f7d6ef1b3ffe836f91388dcd3c Mon Sep 17 00:00:00 2001 From: Kevin Bates Date: Tue, 11 Sep 2018 11:08:05 -0700 Subject: [PATCH] Prevent access through 'NoneType' when closing activity_stream Although I'm unable to reproduce the issue, its a safe change to prevent an AttributeError from occuring ('NoneType' object has no attribute 'close'). The user that reported this is attempting to launch a kernel and I believe the launch only partially completed such that `kernel._activity_stream` did not get established. (This occurred from Jupyter Enterprise Gateway where we deal with remote kernel launches across resource-managed clusters, so things are a bit more involved relative to kernel establishment.) --- notebook/services/kernels/kernelmanager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/notebook/services/kernels/kernelmanager.py b/notebook/services/kernels/kernelmanager.py index 859c9c2d78..45dac8b699 100644 --- a/notebook/services/kernels/kernelmanager.py +++ b/notebook/services/kernels/kernelmanager.py @@ -272,8 +272,9 @@ def shutdown_kernel(self, kernel_id, now=False): """Shutdown a kernel by kernel_id""" self._check_kernel_id(kernel_id) kernel = self._kernels[kernel_id] - kernel._activity_stream.close() - kernel._activity_stream = None + if kernel._activity_stream: + kernel._activity_stream.close() + kernel._activity_stream = None self.stop_buffering(kernel_id) self._kernel_connections.pop(kernel_id, None) self.last_kernel_activity = utcnow()