Show More
@@ -514,12 +514,13 b' class IOPubHandler(AuthenticatedZMQStreamHandler):' | |||||
514 | # from the WebSocket close event. If the WebSocket connection is |
|
514 | # from the WebSocket close event. If the WebSocket connection is | |
515 | # closed before the ZMQ streams are setup, they could be None. |
|
515 | # closed before the ZMQ streams are setup, they could be None. | |
516 | km = self.application.kernel_manager |
|
516 | km = self.application.kernel_manager | |
517 | km.remove_restart_callback( |
|
517 | if self.kernel_id in km: | |
518 | self.kernel_id, self.on_kernel_restarted, |
|
518 | km.remove_restart_callback( | |
519 | ) |
|
519 | self.kernel_id, self.on_kernel_restarted, | |
520 | km.remove_restart_callback( |
|
520 | ) | |
521 | self.kernel_id, self.on_restart_failed, 'dead', |
|
521 | km.remove_restart_callback( | |
522 | ) |
|
522 | self.kernel_id, self.on_restart_failed, 'dead', | |
|
523 | ) | |||
523 | if self.iopub_stream is not None and not self.iopub_stream.closed(): |
|
524 | if self.iopub_stream is not None and not self.iopub_stream.closed(): | |
524 | self.iopub_stream.on_recv(None) |
|
525 | self.iopub_stream.on_recv(None) | |
525 | self.iopub_stream.close() |
|
526 | self.iopub_stream.close() |
@@ -58,11 +58,10 b' class MappingKernelManager(MultiKernelManager):' | |||||
58 |
|
58 | |||
59 | def notebook_for_kernel(self, kernel_id): |
|
59 | def notebook_for_kernel(self, kernel_id): | |
60 | """Return the notebook_id for a kernel_id or None.""" |
|
60 | """Return the notebook_id for a kernel_id or None.""" | |
61 |
|
|
61 | for notebook_id, kid in self._notebook_mapping.iteritems(): | |
62 |
if |
|
62 | if kernel_id == kid: | |
63 |
return notebook_id |
|
63 | return notebook_id | |
64 |
|
|
64 | return None | |
65 | return None |
|
|||
66 |
|
65 | |||
67 | def delete_mapping_for_kernel(self, kernel_id): |
|
66 | def delete_mapping_for_kernel(self, kernel_id): | |
68 | """Remove the kernel/notebook mapping for kernel_id.""" |
|
67 | """Remove the kernel/notebook mapping for kernel_id.""" | |
@@ -70,6 +69,12 b' class MappingKernelManager(MultiKernelManager):' | |||||
70 | if notebook_id is not None: |
|
69 | if notebook_id is not None: | |
71 | del self._notebook_mapping[notebook_id] |
|
70 | del self._notebook_mapping[notebook_id] | |
72 |
|
71 | |||
|
72 | def _handle_kernel_died(self, kernel_id): | |||
|
73 | """notice that a kernel died""" | |||
|
74 | self.log.warn("Kernel %s died, removing from map.", kernel_id) | |||
|
75 | self.delete_mapping_for_kernel(kernel_id) | |||
|
76 | self.remove_kernel(kernel_id, now=True) | |||
|
77 | ||||
73 | def start_kernel(self, notebook_id=None, **kwargs): |
|
78 | def start_kernel(self, notebook_id=None, **kwargs): | |
74 | """Start a kernel for a notebok an return its kernel_id. |
|
79 | """Start a kernel for a notebok an return its kernel_id. | |
75 |
|
80 | |||
@@ -87,8 +92,14 b' class MappingKernelManager(MultiKernelManager):' | |||||
87 | self.set_kernel_for_notebook(notebook_id, kernel_id) |
|
92 | self.set_kernel_for_notebook(notebook_id, kernel_id) | |
88 | self.log.info("Kernel started: %s" % kernel_id) |
|
93 | self.log.info("Kernel started: %s" % kernel_id) | |
89 | self.log.debug("Kernel args: %r" % kwargs) |
|
94 | self.log.debug("Kernel args: %r" % kwargs) | |
|
95 | # register callback for failed auto-restart | |||
|
96 | self.add_restart_callback(kernel_id, | |||
|
97 | lambda : self._handle_kernel_died(kernel_id), | |||
|
98 | 'dead', | |||
|
99 | ) | |||
90 | else: |
|
100 | else: | |
91 | self.log.info("Using existing kernel: %s" % kernel_id) |
|
101 | self.log.info("Using existing kernel: %s" % kernel_id) | |
|
102 | ||||
92 | return kernel_id |
|
103 | return kernel_id | |
93 |
|
104 | |||
94 | # override _check_kernel_id to raise 404 instead of KeyError |
|
105 | # override _check_kernel_id to raise 404 instead of KeyError |
General Comments 0
You need to be logged in to leave comments.
Login now