Using beforeunload to save at exit and kill the kernel.

This commit is contained in:
Brian E. Granger 2011-08-07 12:26:33 -07:00
parent 8cf1812395
commit 188e6271e1
5 changed files with 38 additions and 3 deletions

View File

@ -63,7 +63,7 @@ class KernelHandler(web.RequestHandler):
def delete(self, kernel_id):
rkm = self.application.routing_kernel_manager
self.kill_kernel(kernel_id)
rkm.kill_kernel(kernel_id)
self.set_status(204)
self.finish()

View File

@ -80,10 +80,20 @@ span.section_row_buttons > button {
float: right;
}
#kernel_persist {
float: right;
}
.checkbox_label {
font-size: 85%;
float: right;
padding: 0.3em;
}
.section_row_header {
float: left;
font-size: 85%;
padding: 0.2em 0em;
padding: 0.4em 0em;
font-weight: bold;
}

View File

@ -87,7 +87,7 @@ var IPython = (function (IPython) {
Kernel.prototype.restart = function () {
IPython.kernel_status_widget.status_restarting();
url = this.kernel_url + "/restart"
var url = this.kernel_url + "/restart"
var that = this;
$.post(url, function (kernel_id) {
console.log("Kernel restarted: " + kernel_id);
@ -98,6 +98,14 @@ var IPython = (function (IPython) {
};
Kernel.prototype.kill = function () {
var settings = {
cache : false,
type : "DELETE",
};
$.ajax(this.kernel_url, settings);
};
IPython.Kernel = Kernel;
return IPython;

View File

@ -32,6 +32,17 @@ var IPython = (function (IPython) {
this.element.find('button#save_notebook').click(function () {
IPython.notebook.save_notebook();
});
$(window).bind('beforeunload', function () {
var kill_kernel = $('#kill_kernel').prop('checked');
IPython.notebook.save_notebook();
if (kill_kernel) {
IPython.notebook.kernel.kill();
return "You are about to exit this notebook and kill the kernel.";
} else {
return "You are about the exit this notebook and leave the kernel running.";
};
});
};

View File

@ -127,6 +127,12 @@
</span>
<span class="section_row_header">Actions</span>
</div>
<div class="section_row">
<span id="kernel_persist">
<input type="checkbox" id="kill_kernel"></input>
</span>
<span class="checkbox_label">Kill kernel upon exit:</span>
</div>
</div>
</div>