From 794045f12f5e34804acdf098bfa01a5e12022db3 2014-10-08 18:30:30 From: Jessica B. Hamrick Date: 2014-10-08 18:30:30 Subject: [PATCH] Add restart function to session --- diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 81c3a41..f3753c2 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -78,14 +78,12 @@ define([ * @param {function} [error] - functon executed on ajax error */ Session.prototype.start = function (success, error) { - if (this.kernel !== null) { - throw new Error("session has already been started"); - }; - var that = this; var on_success = function (data, status, xhr) { - 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, that.kernel_model.name); + if (!that.kernel) { + 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, that.kernel_model.name); + } that.events.trigger('kernel_started.Session', {session: that, kernel: that.kernel}); that.kernel._kernel_started(data.kernel); if (success) { @@ -186,6 +184,24 @@ define([ }); }; + Session.prototype.restart = function (options, success, error) { + var that = this; + var start = function () { + if (options && options.notebook_name) { + that.notebook_model.name = options.notebook_name; + } + if (options && options.notebook_path) { + that.notebook_model.path = options.notebook_path; + } + if (options && options.kernel_name) { + that.kernel_model.name = options.kernel_name; + } + that.kernel_model.id = null; + that.start(success, error); + }; + this.delete(start, start); + }; + // Helper functions /**