##// END OF EJS Templates
Shut down kernels in parallel...
Shut down kernels in parallel When stopping the notebook server, it currently sends a shutdown request to each kernel and then waits for the process to finish. This can be slow if you have several kernels running. This makes it issues all the shutdown requests before waiting on the processes, so shutdown happens in parallel. KernelManager (and MultiKernelManager) gain three new public API methods to allow this: * request_shutdown (promoted from a private method) * wait_shutdown (refactored out of shutdown_kernel) * cleanup (refactored out of shutdown_kernel)

File last commit:

r15994:d1ebd1b6
r16510:633371e5
Show More
notificationarea.js
235 lines | 9.1 KiB | application/javascript | JavascriptLexer
Matthias BUSSONNIER
beginning notification area
r8011 //----------------------------------------------------------------------------
// Copyright (C) 2012 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
// Notification widget
//============================================================================
var IPython = (function (IPython) {
"use strict";
var utils = IPython.utils;
var NotificationArea = function (selector) {
this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
}
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 this.widget_dict = {};
Matthias BUSSONNIER
beginning notification area
r8011 };
NotificationArea.prototype.temp_message = function (msg, timeout, css_class) {
var uuid = utils.uuid();
Matthias BUSSONNIER
jslint 1
r8204 if( css_class == 'danger') {css_class = 'ui-state-error';}
if( css_class == 'warning') {css_class = 'ui-state-highlight';}
Matthias BUSSONNIER
beginning notification area
r8011 var tdiv = $('<div>')
.attr('id',uuid)
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 .addClass('notification_widget ui-widget ui-widget-content ui-corner-all')
Matthias BUSSONNIER
beginning notification area
r8011 .addClass('border-box-sizing')
.addClass(css_class)
.hide()
.text(msg);
$(this.selector).append(tdiv);
Matthias BUSSONNIER
trap undefined timout
r8012 var tmout = Math.max(1500,(timeout||1500));
Matthias BUSSONNIER
beginning notification area
r8011 tdiv.fadeIn(100);
setTimeout(function () {
tdiv.fadeOut(100, function () {tdiv.remove();});
Matthias BUSSONNIER
jslint 1
r8204 }, tmout);
Matthias BUSSONNIER
beginning notification area
r8011 };
Matthias BUSSONNIER
jslint 1
r8204 NotificationArea.prototype.widget = function(name) {
Paul Ivanov
rename css class names to be consistent with current style
r15847 if(this.widget_dict[name] === undefined) {
Matthias BUSSONNIER
jslint 1
r8204 return this.new_notification_widget(name);
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 }
Mikhail Korobov
Some bugs in js (mostly scoping bugs) are fixed
r8839 return this.get_widget(name);
Matthias BUSSONNIER
jslint 1
r8204 };
Matthias BUSSONNIER
tweek notebook notification behavior
r8074
NotificationArea.prototype.get_widget = function(name) {
Paul Ivanov
rename css class names to be consistent with current style
r15847 if(this.widget_dict[name] === undefined) {
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 throw('no widgets with this name');
}
return this.widget_dict[name];
Matthias BUSSONNIER
jslint 1
r8204 };
Matthias BUSSONNIER
tweek notebook notification behavior
r8074
Matthias BUSSONNIER
call init method
r8048 NotificationArea.prototype.new_notification_widget = function(name) {
Paul Ivanov
rename css class names to be consistent with current style
r15847 if(this.widget_dict[name] !== undefined) {
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 throw('widget with that name already exists ! ');
}
Matthias BUSSONNIER
call init method
r8048 var div = $('<div/>').attr('id','notification_'+name);
Matthias BUSSONNIER
jslint 1
r8204 $(this.selector).append(div);
this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 return this.widget_dict[name];
Matthias BUSSONNIER
jslint 1
r8204 };
Matthias BUSSONNIER
tweek notebook notification behavior
r8074
NotificationArea.prototype.init_notification_widgets = function() {
var knw = this.new_notification_widget('kernel');
Brian E. Granger
Add edit/command mode indicator.
r15115 var $kernel_ind_icon = $("#kernel_indicator_icon");
var $modal_ind_icon = $("#modal_indicator_icon");
// Command/Edit mode
$([IPython.events]).on('edit_mode.Notebook',function () {
IPython.save_widget.update_document_title();
Paul Ivanov
rename css class names to be consistent with current style
r15847 $modal_ind_icon.attr('class','edit_mode_icon').attr('title','Edit Mode');
Brian E. Granger
Add edit/command mode indicator.
r15115 });
$([IPython.events]).on('command_mode.Notebook',function () {
IPython.save_widget.update_document_title();
Paul Ivanov
rename css class names to be consistent with current style
r15847 $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode');
Brian E. Granger
Add edit/command mode indicator.
r15115 });
Matthias BUSSONNIER
tweek notebook notification behavior
r8074
Paul Ivanov
better fix for starting with Command Mode icon
r15809 // Implicitly start off in Command mode, switching to Edit mode will trigger event
Paul Ivanov
rename css class names to be consistent with current style
r15847 $modal_ind_icon.attr('class','command-mode_icon').attr('title','Command Mode');
Paul Ivanov
better fix for starting with Command Mode icon
r15809
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 // Kernel events
$([IPython.events]).on('status_idle.Kernel',function () {
IPython.save_widget.update_document_title();
Paul Ivanov
rename css class names to be consistent with current style
r15847 $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle');
Matthias BUSSONNIER
more subtle kernel indicator...
r15042 });
Matthias BUSSONNIER
tweek notebook notification behavior
r8074
$([IPython.events]).on('status_busy.Kernel',function () {
window.document.title='(Busy) '+window.document.title;
Paul Ivanov
rename css class names to be consistent with current style
r15847 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 });
$([IPython.events]).on('status_restarting.Kernel',function () {
IPython.save_widget.update_document_title();
MinRK
handle new autorestart javascript-side
r10316 knw.set_message("Restarting kernel", 2000);
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 });
$([IPython.events]).on('status_interrupting.Kernel',function () {
Brian E. Granger
Added platform dep. logic.
r14816 knw.set_message("Interrupting kernel", 2000);
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 });
MinRK
Correct initial state of kernel status indicator...
r15737
// Start the kernel indicator in the busy state, and send a kernel_info request.
// When the kernel_info reply arrives, the kernel is idle.
Paul Ivanov
rename css class names to be consistent with current style
r15847 $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy');
MinRK
Correct initial state of kernel status indicator...
r15737
$([IPython.events]).on('status_started.Kernel', function (evt, data) {
data.kernel.kernel_info(function () {
$([IPython.events]).trigger('status_idle.Kernel');
});
});
Matthias BUSSONNIER
tweek notebook notification behavior
r8074
$([IPython.events]).on('status_dead.Kernel',function () {
MinRK
bootstrap dialogs
r10895 var msg = 'The kernel has died, and the automatic restart has failed.' +
MinRK
handle new autorestart javascript-side
r10316 ' It is possible the kernel cannot be restarted.' +
' If you are not able to restart the kernel, you will still be able to save' +
' the notebook, but running code will no longer work until the notebook' +
MinRK
bootstrap dialogs
r10895 ' is reopened.';
IPython.dialog.modal({
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 title: "Dead kernel",
MinRK
bootstrap dialogs
r10895 body : msg,
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 buttons : {
MinRK
bootstrap dialogs
r10895 "Manual Restart": {
class: "btn-danger",
click: function () {
$([IPython.events]).trigger('status_restarting.Kernel');
IPython.notebook.start_kernel();
}
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 },
MinRK
bootstrap dialogs
r10895 "Don't restart": {}
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 }
});
});
Brian E. Granger
Refactoring WebSocket connection failure logic....
r9222 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
var kernel = data.kernel;
var ws_url = data.ws_url;
var early = data.early;
var msg;
if (!early) {
knw.set_message('Reconnecting WebSockets', 1000);
setTimeout(function () {
kernel.start_channels();
}, 5000);
return;
}
Paul Ivanov
rename css class names to be consistent with current style
r15847 console.log('WebSocket connection failed: ', ws_url);
Kieran O'Mahony
Fix error message typo on web socket fail
r14955 msg = "A WebSocket connection could not be established." +
Brian E. Granger
Refactoring WebSocket connection failure logic....
r9222 " You will NOT be able to run code. Check your" +
" network connection or notebook server configuration.";
MinRK
bootstrap dialogs
r10895 IPython.dialog.modal({
Brian E. Granger
Refactoring WebSocket connection failure logic....
r9222 title: "WebSocket connection failed",
MinRK
bootstrap dialogs
r10895 body: msg,
Brian E. Granger
Refactoring WebSocket connection failure logic....
r9222 buttons : {
MinRK
bootstrap dialogs
r10895 "OK": {},
"Reconnect": {
click: function () {
knw.set_message('Reconnecting WebSockets', 1000);
setTimeout(function () {
kernel.start_channels();
}, 5000);
}
Brian E. Granger
Refactoring WebSocket connection failure logic....
r9222 }
}
});
});
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 var nnw = this.new_notification_widget('notebook');
// Notebook events
$([IPython.events]).on('notebook_loading.Notebook', function () {
nnw.set_message("Loading notebook",500);
});
$([IPython.events]).on('notebook_loaded.Notebook', function () {
nnw.set_message("Notebook loaded",500);
});
$([IPython.events]).on('notebook_saving.Notebook', function () {
nnw.set_message("Saving notebook",500);
});
$([IPython.events]).on('notebook_saved.Notebook', function () {
nnw.set_message("Notebook saved",2000);
});
Paul Ivanov
prevent saving of partially loaded notebooks...
r15881 $([IPython.events]).on('notebook_save_failed.Notebook', function (evt, xhr, status, data) {
Paul Ivanov
address PR feedback
r15994 nnw.set_message(data || "Notebook save failed");
Matthias BUSSONNIER
tweek notebook notification behavior
r8074 });
MinRK
add some checkpoint messages to the notification area
r10502
// Checkpoint events
$([IPython.events]).on('checkpoint_created.Notebook', function (evt, data) {
var msg = "Checkpoint created";
if (data.last_modified) {
var d = new Date(data.last_modified);
msg = msg + ": " + d.format("HH:MM:ss");
}
nnw.set_message(msg, 2000);
});
$([IPython.events]).on('checkpoint_failed.Notebook', function () {
nnw.set_message("Checkpoint failed");
});
$([IPython.events]).on('checkpoint_deleted.Notebook', function () {
nnw.set_message("Checkpoint deleted", 500);
});
$([IPython.events]).on('checkpoint_delete_failed.Notebook', function () {
nnw.set_message("Checkpoint delete failed");
});
$([IPython.events]).on('checkpoint_restoring.Notebook', function () {
nnw.set_message("Restoring to checkpoint...", 500);
});
$([IPython.events]).on('checkpoint_restore_failed.Notebook', function () {
nnw.set_message("Checkpoint restore failed");
});
Matthias BUSSONNIER
tweek notebook notification behavior
r8074
MinRK
add autosave timer...
r10505 // Autosave events
$([IPython.events]).on('autosave_disabled.Notebook', function () {
nnw.set_message("Autosave disabled", 2000);
});
$([IPython.events]).on('autosave_enabled.Notebook', function (evt, interval) {
nnw.set_message("Saving every " + interval / 1000 + "s", 1000);
});
Matthias BUSSONNIER
jslint 1
r8204 };
Matthias BUSSONNIER
call init method
r8048
Matthias BUSSONNIER
beginning notification area
r8011 IPython.NotificationArea = NotificationArea;
return IPython;
}(IPython));