Merge pull request #6558 from jhamrick/kernel-start-failure

Handle kernel start failures more gracefully
This commit is contained in:
Matthias Bussonnier 2014-10-03 09:04:00 +02:00
commit eeb9cb0209
4 changed files with 55 additions and 3 deletions

View File

@ -10,6 +10,7 @@ from tornado import web
from ...base.handlers import IPythonHandler, json_errors
from IPython.utils.jsonutil import date_default
from IPython.html.utils import url_path_join, url_escape
from IPython.kernel.kernelspec import NoSuchKernel
class SessionRootHandler(IPythonHandler):
@ -52,7 +53,17 @@ class SessionRootHandler(IPythonHandler):
if sm.session_exists(name=name, path=path):
model = sm.get_session(name=name, path=path)
else:
model = sm.create_session(name=name, path=path, kernel_name=kernel_name)
try:
model = sm.create_session(name=name, path=path, kernel_name=kernel_name)
except NoSuchKernel:
msg = ("The '%s' kernel is not available. Please pick another "
"suitable kernel instead, or install that kernel." % kernel_name)
status_msg = '%s not found' % kernel_name
self.log.warn('Kernel not found: %s' % kernel_name)
self.set_status(501)
self.finish(json.dumps(dict(message=msg, short_message=status_msg)))
return
location = url_path_join(self.base_url, 'api', 'sessions', model['id'])
self.set_header('Location', url_escape(location))
self.set_status(201)

View File

@ -159,7 +159,7 @@ define([
});
});
this.events.on('status_dead.Kernel',function () {
this.events.on('status_restart_failed.Kernel',function () {
var msg = 'The kernel has died, and the automatic restart has failed.' +
' It is possible the kernel cannot be restarted.' +
' If you are not able to restart the kernel, you will still be able to save' +
@ -184,6 +184,47 @@ define([
});
});
this.events.on('start_failed.Session',function (session, xhr, status, error) {
var full = status.responseJSON.message;
var short = status.responseJSON.short_message || 'Kernel error';
var traceback = status.responseJSON.traceback;
var showMsg = function () {
var msg = $('<div/>').append($('<p/>').text(full));
var cm, cm_elem;
if (traceback) {
cm_elem = $('<div/>')
.css('margin-top', '1em')
.css('padding', '1em')
.addClass('output_scroll');
msg.append(cm_elem);
cm = CodeMirror(cm_elem.get(0), {
mode: "python",
readOnly : true
});
cm.setValue(traceback);
}
dialog.modal({
title: "Failed to start the kernel",
body : msg,
keyboard_manager: that.keyboard_manager,
notebook: that.notebook,
open: $.proxy(cm.refresh, cm),
buttons : {
"Ok": { class: 'btn-primary' }
}
});
return false;
};
that.save_widget.update_document_title();
$kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead');
knw.danger(short, undefined, showMsg);
});
this.events.on('websocket_closed.Kernel', function (event, data) {
var kernel = data.kernel;
var ws_url = data.ws_url;

View File

@ -560,6 +560,7 @@ define([
} else if (execution_state === 'dead') {
this.stop_channels();
this.events.trigger('status_dead.Kernel', {kernel: this});
this.events.trigger('status_restart_failed.Kernel', {kernel: this});
}
};

View File

@ -112,7 +112,6 @@ define([
Session.prototype._handle_start_failure = function (xhr, status, error) {
this.events.trigger('start_failed.Session', [this, xhr, status, error]);
this.events.trigger('status_dead.Kernel');
};
/**