28
28
29
29
30
30
class MappingKernelManager (MultiKernelManager ):
31
- """A KernelManager that handles file mapping and HTTP error handling"""
31
+ """A KernelManager that handles
32
+ - File mapping
33
+ - HTTP error handling
34
+ - Kernel message filtering
35
+ """
32
36
33
37
@default ('kernel_manager_class' )
34
38
def _default_kernel_manager_class (self ):
@@ -93,15 +97,15 @@ def _update_root_dir(self, proposal):
93
97
no frontends are connected.
94
98
"""
95
99
)
96
-
100
+
97
101
kernel_info_timeout = Float (60 , config = True ,
98
102
help = """Timeout for giving up on a kernel (in seconds).
99
103
100
104
On starting and restarting kernels, we check whether the
101
105
kernel is running and responsive by sending kernel_info_requests.
102
106
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)
107
+ before being presumed dead.
108
+ This affects the MappingKernelManager (which handles kernel restarts)
105
109
and the ZMQChannelsHandler (which handles the startup).
106
110
"""
107
111
)
@@ -118,6 +122,12 @@ def __init__(self, **kwargs):
118
122
super (MappingKernelManager , self ).__init__ (** kwargs )
119
123
self .last_kernel_activity = utcnow ()
120
124
125
+ allowed_message_types = List (trait = Unicode (), config = True ,
126
+ help = """White list of allowed kernel message types.
127
+ When the list is empty, all message types are allowed.
128
+ """
129
+ )
130
+
121
131
#-------------------------------------------------------------------------
122
132
# Methods for managing kernels and sessions
123
133
#-------------------------------------------------------------------------
@@ -287,32 +297,32 @@ def restart_kernel(self, kernel_id):
287
297
# return a Future that will resolve when the kernel has successfully restarted
288
298
channel = kernel .connect_shell ()
289
299
future = Future ()
290
-
300
+
291
301
def finish ():
292
302
"""Common cleanup when restart finishes/fails for any reason."""
293
303
if not channel .closed ():
294
304
channel .close ()
295
305
loop .remove_timeout (timeout )
296
306
kernel .remove_restart_callback (on_restart_failed , 'dead' )
297
-
307
+
298
308
def on_reply (msg ):
299
309
self .log .debug ("Kernel info reply received: %s" , kernel_id )
300
310
finish ()
301
311
if not future .done ():
302
312
future .set_result (msg )
303
-
313
+
304
314
def on_timeout ():
305
315
self .log .warning ("Timeout waiting for kernel_info_reply: %s" , kernel_id )
306
316
finish ()
307
317
if not future .done ():
308
318
future .set_exception (gen .TimeoutError ("Timeout waiting for restart" ))
309
-
319
+
310
320
def on_restart_failed ():
311
321
self .log .warning ("Restarting kernel failed: %s" , kernel_id )
312
322
finish ()
313
323
if not future .done ():
314
324
future .set_exception (RuntimeError ("Restart failed" ))
315
-
325
+
316
326
kernel .add_restart_callback (on_restart_failed , 'dead' )
317
327
kernel .session .send (channel , "kernel_info_request" )
318
328
channel .on_recv (on_reply )
@@ -366,7 +376,7 @@ def _check_kernel_id(self, kernel_id):
366
376
367
377
def start_watching_activity (self , kernel_id ):
368
378
"""Start watching IOPub messages on a kernel for activity.
369
-
379
+
370
380
- update last_activity on every message
371
381
- record execution_state from status messages
372
382
"""
0 commit comments