diff --git a/IPython/html/static/notebook/js/notificationarea.js b/IPython/html/static/notebook/js/notificationarea.js index bc4abb5..9211ed1 100644 --- a/IPython/html/static/notebook/js/notificationarea.js +++ b/IPython/html/static/notebook/js/notificationarea.js @@ -121,15 +121,13 @@ define([ // Implicitly start off in Command mode, switching to Edit mode will trigger event $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode'); - // Kernel events - this.events.on('status_idle.Kernel',function () { - that.save_widget.update_document_title(); - $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle'); + // Kernel events + this.events.on('status_started.Kernel', function () { + knw.info("Kernel Started", 500); }); - this.events.on('status_busy.Kernel',function () { - window.document.title='(Busy) '+window.document.title; - $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); + this.events.on('status_connected.Kernel', function () { + knw.info("Websockets Connected", 500); }); this.events.on('status_restarting.Kernel',function () { @@ -137,33 +135,41 @@ define([ knw.set_message("Restarting kernel", 2000); }); - this.events.on('status_dead.Kernel',function () { - that.save_widget.update_document_title(); - knw.danger("Dead kernel"); - $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead'); - }); - this.events.on('status_interrupting.Kernel',function () { knw.set_message("Interrupting kernel", 2000); }); - - // Start the kernel indicator in the busy state, and send a kernel_info request. - // When the kernel_info reply arrives, the kernel is idle. - $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); - this.events.on('status_started.Kernel', function (evt, data) { - knw.info("Kernel Started", 500); + this.events.on('status_disconnected.Kernel', function () { + $kernel_ind_icon + .attr('class', 'kernel_disconnected_icon') + .attr('title', 'No Connection to Kernel'); }); - this.events.on('status_connected.Kernel', function (evt, data) { - knw.info("Websockets Connected", 500); - that.events.trigger('status_busy.Kernel'); - data.kernel.kernel_info(function () { - that.events.trigger('status_idle.Kernel'); + this.events.on('early_disconnect.Kernel', function (ws_url) { + var msg = "A WebSocket connection could not be established." + + " You will NOT be able to run code. Check your" + + " network connection or notebook server configuration."; + dialog.modal({ + title: "WebSocket connection failed", + body: msg, + keyboard_manager: that.keyboard_manager, + notebook: that.notebook, + buttons : { + "OK": {}, + "Reconnect": { + click: that.notebook.kernel.reconnect + } + } }); }); - this.events.on('status_restart_failed.Kernel',function () { + this.events.on('status_dead.Kernel',function () { + that.save_widget.update_document_title(); + knw.danger("Dead kernel"); + $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead'); + }); + + this.events.on('status_dead.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' + @@ -178,10 +184,7 @@ define([ buttons : { "Manual Restart": { class: "btn-danger", - click: function () { - that.events.trigger('status_restarting.Kernel'); - that.notebook.start_kernel(); - } + click: that.notebook.kernel.restart }, "Don't restart": {} } @@ -229,45 +232,19 @@ define([ knw.danger(short, undefined, showMsg); }); - this.events.on('status_disconnected.Kernel', function (event, data) { - var kernel = data.kernel; - var ws_url = data.ws_url; - var early = data.early; - var msg; + this.events.on('status_idle.Kernel',function () { + that.save_widget.update_document_title(); + $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle'); + }); - $kernel_ind_icon - .attr('class', 'kernel_disconnected_icon') - .attr('title', 'No Connection to Kernel'); - - if (!early) { - knw.warning('Reconnecting'); - setTimeout(function () { - kernel.start_channels(); - }, 5000); - return; - } - console.log('WebSocket connection failed: ', ws_url); - msg = "A WebSocket connection could not be established." + - " You will NOT be able to run code. Check your" + - " network connection or notebook server configuration."; - dialog.modal({ - title: "WebSocket connection failed", - body: msg, - keyboard_manager: that.keyboard_manager, - notebook: that.notebook, - buttons : { - "OK": {}, - "Reconnect": { - click: function () { - knw.warning('Reconnecting'); - setTimeout(function () { - kernel.start_channels(); - }, 5000); - } - } - } - }); + this.events.on('status_busy.Kernel',function () { + window.document.title='(Busy) '+window.document.title; + $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); }); + + // Start the kernel indicator in the busy state, and send a kernel_info request. + // When the kernel_info reply arrives, the kernel is idle. + $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); }; /** diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index 4aac242..3574b8c 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -176,6 +176,9 @@ define([ * POST /api/kernels/[:kernel_id]/restart */ Kernel.prototype.restart = function (success, error) { + this.events.trigger('status_restarting.Kernel', {kernel: this}); + this.stop_channels(); + var that = this; var on_success = function (data, status, xhr) { that._kernel_started(data, status, xhr); @@ -195,6 +198,18 @@ define([ }); }; + /** + * Not actually a HTTP request, but useful function nonetheless + * for reconnecting to the kernel if the connection is somehow lost + */ + Kernel.prototype.reconnect = function () { + this.events.trigger('status_reconnecting.Kernel'); + var that = this; + setTimeout(function () { + that.start_channels(); + }, 5000); + }; + Kernel.prototype._on_success = function (success) { var that = this; return function (data, status, xhr) { @@ -224,9 +239,12 @@ define([ this.start_channels(); }; - Kernel.prototype._kernel_restarting = function () { - this.events.trigger('status_restarting.Kernel', {kernel: this}); - this.stop_channels(); + Kernel.prototype._kernel_connected = function () { + var that = this; + this.events.trigger('status_connected.Kernel'); + this.kernel_info(function () { + that.events.trigger('status_idle.Kernel'); + }); }; Kernel.prototype._kernel_dead = function () { @@ -234,12 +252,6 @@ define([ this.stop_channels(); }; - Kernel.prototype._ws_closed = function(ws_url, early) { - this.stop_channels(); - this.events.trigger('status_disconnected.Kernel', - {ws_url: ws_url, kernel: this, early: early} - ); - }; /** * Start the `shell`and `iopub` channels. @@ -325,6 +337,17 @@ define([ } }; + Kernel.prototype._ws_closed = function(ws_url, early) { + this.stop_channels(); + this.events.trigger('status_disconnected.Kernel'); + if (!early) { + this.reconnect(); + } else { + console.log('WebSocket connection failed: ', ws_url); + this.events.trigger('early_disconnect.Kernel', ws_url); + } + }; + /** * Stop the websocket channels. * @method stop_channels diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 5451d63..fbca98f 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -50,7 +50,6 @@ define([ Session.prototype.start = function (success, error) { var that = this; var on_success = function (data, status, xhr) { - console.log("Session started: ", data.id); var kernel_service_url = utils.url_path_join(that.base_url, "api/kernels"); that.kernel = new kernel.Kernel( kernel_service_url, that.ws_url, that.notebook,