diff --git a/IPython/html/services/sessions/handlers.py b/IPython/html/services/sessions/handlers.py index 98def21a5..addfd887a 100644 --- a/IPython/html/services/sessions/handlers.py +++ b/IPython/html/services/sessions/handlers.py @@ -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) diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index 81f650bfe..bfd15d5ba 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -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 = $('
').append($('').text(full)); + var cm, cm_elem; + + if (traceback) { + cm_elem = $('') + .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; diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index 9b4937a22..e1ec7e4e9 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -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}); } }; diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 14a93af70..d8d5b5663 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -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'); }; /**