Skip to content

Commit 56055fb

Browse files
committed
add kernel_info_timeout traitlet to wait for slow kernel startups
This affects both the MappingKernelManager and the ZMQChannelsHandler(by extension). This allows one setting to apply to both startup andrestarting.
1 parent 459b92c commit 56055fb

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

notebook/services/kernels/handlers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class ZMQChannelsHandler(AuthenticatedZMQStreamHandler):
104104

105105
@property
106106
def kernel_info_timeout(self):
107-
return self.settings.get('kernel_info_timeout', 10)
107+
km_default = self.kernel_manager.kernel_info_timeout
108+
return self.settings.get('kernel_info_timeout', km_default)
108109

109110
@property
110111
def iopub_msg_rate_limit(self):

notebook/services/kernels/kernelmanager.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from jupyter_client.session import Session
2020
from jupyter_client.multikernelmanager import MultiKernelManager
2121
from traitlets import (Any, Bool, Dict, List, Unicode, TraitError, Integer,
22-
Instance, default, validate
22+
Float, Instance, default, validate
2323
)
2424

2525
from notebook.utils import to_os_path, exists
@@ -93,6 +93,22 @@ def _update_root_dir(self, proposal):
9393
no frontends are connected.
9494
"""
9595
)
96+
97+
kernel_info_timeout = Float(60, config=True,
98+
help="""Timeout for giving up on a kernel (in seconds).
99+
100+
On starting and restarting kernels, we check whether the
101+
kernel is running and responsive by sending kernel_info_requests.
102+
This sets the timeout in seconds for how long the kernel can take
103+
before being presumed dead.
104+
This affects the MappingKernelManager (which handles kernel restarts)
105+
and the ZMQChannelsHandler (which handles the startup).
106+
"""
107+
)
108+
109+
kernel_info_timeout = Integer(30, config=True,
110+
help="""This changes the amount of time that we wait for the kernel_info_reply the kernel restart is requested."""
111+
)
96112

97113
_kernel_buffers = Any()
98114
@default('_kernel_buffers')
@@ -305,7 +321,7 @@ def on_restart_failed():
305321
kernel.session.send(channel, "kernel_info_request")
306322
channel.on_recv(on_reply)
307323
loop = IOLoop.current()
308-
timeout = loop.add_timeout(loop.time() + 30, on_timeout)
324+
timeout = loop.add_timeout(loop.time() + self.kernel_info_timeout, on_timeout)
309325
return future
310326

311327
def notify_connect(self, kernel_id):
@@ -434,4 +450,3 @@ def cull_kernel_if_idle(self, kernel_id):
434450
self.log.warning("Culling '%s' kernel '%s' (%s) with %d connections due to %s seconds of inactivity.",
435451
kernel.execution_state, kernel.kernel_name, kernel_id, connections, idle_duration)
436452
self.shutdown_kernel(kernel_id)
437-

0 commit comments

Comments
 (0)