##// END OF EJS Templates
cleanup kernelspec loading...
Min RK -
Show More
@@ -126,28 +126,27 define([
126 }
126 }
127 };
127 };
128
128
129 KernelSelector.prototype.change_kernel = function (kernel_name) {
129 KernelSelector.prototype.set_kernel = function (kernel_name) {
130 /**
130 /** set the kernel by name, ensuring kernelspecs have been loaded, first */
131 * TODO, have a methods to set kernel spec directly ?
131 var that = this;
132 **/
132 return this.loaded.then(function () {
133 that._set_kernel(kernel_name);
134 });
135 };
136
137 KernelSelector.prototype._set_kernel = function (kernel_name) {
138 /** Actually set the kernel (kernelspecs have been loaded) */
139 console.log("_set_kernel", kernel_name, this.current_selection);
133 if (kernel_name === this.current_selection) {
140 if (kernel_name === this.current_selection) {
141 // only trigger event if value changed
134 return;
142 return;
135 }
143 }
136 var ks = this.kernelspecs[kernel_name];
144 var ks = this.kernelspecs[kernel_name];
137
145 if (this.notebook._session_starting) {
138 try {
146 console.log("Cannot change kernel while waiting for pending session start.");
139 this.notebook.start_session(kernel_name);
140 } catch (e) {
141 if (e.name === 'SessionAlreadyStarting') {
142 console.log("Cannot change kernel while waiting for pending session start.");
143 } else {
144 // unhandled error
145 throw e;
146 }
147 // only trigger spec_changed if change was successful
148 return;
147 return;
149 }
148 }
150 console.log('spec', kernel_name, ks);
149 this.current_selection = kernel_name;
151 this.events.trigger('spec_changed.Kernel', ks);
150 this.events.trigger('spec_changed.Kernel', ks);
152 };
151 };
153
152
@@ -189,13 +188,7 define([
189 this.events.on('spec_changed.Kernel', $.proxy(this._spec_changed, this));
188 this.events.on('spec_changed.Kernel', $.proxy(this._spec_changed, this));
190
189
191 this.events.on('kernel_created.Session', function (event, data) {
190 this.events.on('kernel_created.Session', function (event, data) {
192 if (data.kernel.name !== that.current_selection) {
191 that.set_kernel(data.kernel.name);
193 // If we created a 'python' session, we only know if it's Python
194 // 3 or 2 on the server's reply, so we fire the event again to
195 // set things up.
196 var ks = that.kernelspecs[data.kernel.name];
197 that.events.trigger('spec_changed.Kernel', ks);
198 }
199 });
192 });
200
193
201 var logo_img = this.element.find("img.current_kernel_logo");
194 var logo_img = this.element.find("img.current_kernel_logo");
@@ -248,6 +248,10 define([
248 this.events.on('spec_changed.Kernel', function(event, data) {
248 this.events.on('spec_changed.Kernel', function(event, data) {
249 that.metadata.kernelspec =
249 that.metadata.kernelspec =
250 {name: data.name, display_name: data.spec.display_name};
250 {name: data.name, display_name: data.spec.display_name};
251 // start session if the current session isn't already correct
252 if (!(this.session && this.session.kernel && this.session.kernel.name === data.name)) {
253 that.start_session(data.name);
254 }
251 });
255 });
252
256
253 this.events.on('kernel_ready.Kernel', function(event, data) {
257 this.events.on('kernel_ready.Kernel', function(event, data) {
@@ -1763,19 +1767,6 define([
1763 this.notebook_path = data.path;
1767 this.notebook_path = data.path;
1764 var trusted = true;
1768 var trusted = true;
1765
1769
1766 // Trigger an event changing the kernel spec - this will set the default
1767 // codemirror mode
1768 if (this.metadata.kernelspec !== undefined) {
1769 // TODO shoudl probably not trigger here,
1770 // should call the kernel selector, or custom.{js|css} not loaded.
1771 if(this.kernel_selector){
1772 // technically not perfect, we should check that the kernelspec matches
1773 this.kernel_selector.change_kernel(this.metadata.kernelspec.name);
1774 } else {
1775 console.log('do not have handle on kernel_selector');
1776 }
1777 }
1778
1779 // Set the codemirror mode from language_info metadata
1770 // Set the codemirror mode from language_info metadata
1780 if (this.metadata.language_info !== undefined) {
1771 if (this.metadata.language_info !== undefined) {
1781 var langinfo = this.metadata.language_info;
1772 var langinfo = this.metadata.language_info;
@@ -2193,8 +2184,6 define([
2193 this.nbformat_minor = nbmodel.nbformat_minor;
2184 this.nbformat_minor = nbmodel.nbformat_minor;
2194 }
2185 }
2195
2186
2196 // Create the session after the notebook is completely loaded to prevent
2197 // code execution upon loading, which is a security risk.
2198 if (this.session === null) {
2187 if (this.session === null) {
2199 var kernel_name;
2188 var kernel_name;
2200 if (this.metadata.kernelspec) {
2189 if (this.metadata.kernelspec) {
@@ -2203,7 +2192,14 define([
2203 } else {
2192 } else {
2204 kernel_name = utils.get_url_param('kernel_name');
2193 kernel_name = utils.get_url_param('kernel_name');
2205 }
2194 }
2206 this.start_session(kernel_name);
2195 if (kernel_name) {
2196 // setting kernel_name here triggers start_session
2197 this.kernel_selector.set_kernel(kernel_name);
2198 } else {
2199 // start a new session with the server's default kernel
2200 // spec_changed events will fire after kernel is loaded
2201 this.start_session();
2202 }
2207 }
2203 }
2208 // load our checkpoint list
2204 // load our checkpoint list
2209 this.list_checkpoints();
2205 this.list_checkpoints();
General Comments 0
You need to be logged in to leave comments. Login now