Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Using beforeunload to save at exit and kill the kernel.

  • Loading branch information...
commit 7640e547e81ace6d29ef4bc8afb1c051f1531fa5 1 parent 708c73e
@ellisonbg ellisonbg authored
View
2  IPython/frontend/html/notebook/handlers.py
@@ -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
12 IPython/frontend/html/notebook/static/css/notebook.css
@@ -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
10 IPython/frontend/html/notebook/static/js/kernel.js
@@ -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
11 IPython/frontend/html/notebook/static/js/savewidget.js
@@ -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
6 IPython/frontend/html/notebook/templates/notebook.html
@@ -127,6 +127,12 @@ <h3 class="section_header">Kernel</h3>
</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>
Please sign in to comment.
Something went wrong with that request. Please try again.