Show More
@@ -121,15 +121,13 define([ | |||||
121 | // Implicitly start off in Command mode, switching to Edit mode will trigger event |
|
121 | // Implicitly start off in Command mode, switching to Edit mode will trigger event | |
122 | $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode'); |
|
122 | $modal_ind_icon.attr('class','command_mode_icon').attr('title','Command Mode'); | |
123 |
|
123 | |||
124 | // Kernel events |
|
124 | // Kernel events | |
125 |
this.events.on('status_ |
|
125 | this.events.on('status_started.Kernel', function () { | |
126 | that.save_widget.update_document_title(); |
|
126 | knw.info("Kernel Started", 500); | |
127 | $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle'); |
|
|||
128 | }); |
|
127 | }); | |
129 |
|
128 | |||
130 |
this.events.on('status_ |
|
129 | this.events.on('status_connected.Kernel', function () { | |
131 | window.document.title='(Busy) '+window.document.title; |
|
130 | knw.info("Websockets Connected", 500); | |
132 | $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); |
|
|||
133 | }); |
|
131 | }); | |
134 |
|
132 | |||
135 | this.events.on('status_restarting.Kernel',function () { |
|
133 | this.events.on('status_restarting.Kernel',function () { | |
@@ -137,33 +135,41 define([ | |||||
137 | knw.set_message("Restarting kernel", 2000); |
|
135 | knw.set_message("Restarting kernel", 2000); | |
138 | }); |
|
136 | }); | |
139 |
|
137 | |||
140 | this.events.on('status_dead.Kernel',function () { |
|
|||
141 | that.save_widget.update_document_title(); |
|
|||
142 | knw.danger("Dead kernel"); |
|
|||
143 | $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead'); |
|
|||
144 | }); |
|
|||
145 |
|
||||
146 | this.events.on('status_interrupting.Kernel',function () { |
|
138 | this.events.on('status_interrupting.Kernel',function () { | |
147 | knw.set_message("Interrupting kernel", 2000); |
|
139 | knw.set_message("Interrupting kernel", 2000); | |
148 | }); |
|
140 | }); | |
149 |
|
||||
150 | // Start the kernel indicator in the busy state, and send a kernel_info request. |
|
|||
151 | // When the kernel_info reply arrives, the kernel is idle. |
|
|||
152 | $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); |
|
|||
153 |
|
141 | |||
154 |
this.events.on('status_ |
|
142 | this.events.on('status_disconnected.Kernel', function () { | |
155 | knw.info("Kernel Started", 500); |
|
143 | $kernel_ind_icon | |
|
144 | .attr('class', 'kernel_disconnected_icon') | |||
|
145 | .attr('title', 'No Connection to Kernel'); | |||
156 | }); |
|
146 | }); | |
157 |
|
147 | |||
158 |
this.events.on(' |
|
148 | this.events.on('early_disconnect.Kernel', function (ws_url) { | |
159 | knw.info("Websockets Connected", 500); |
|
149 | var msg = "A WebSocket connection could not be established." + | |
160 | that.events.trigger('status_busy.Kernel'); |
|
150 | " You will NOT be able to run code. Check your" + | |
161 | data.kernel.kernel_info(function () { |
|
151 | " network connection or notebook server configuration."; | |
162 | that.events.trigger('status_idle.Kernel'); |
|
152 | dialog.modal({ | |
|
153 | title: "WebSocket connection failed", | |||
|
154 | body: msg, | |||
|
155 | keyboard_manager: that.keyboard_manager, | |||
|
156 | notebook: that.notebook, | |||
|
157 | buttons : { | |||
|
158 | "OK": {}, | |||
|
159 | "Reconnect": { | |||
|
160 | click: that.notebook.kernel.reconnect | |||
|
161 | } | |||
|
162 | } | |||
163 | }); |
|
163 | }); | |
164 | }); |
|
164 | }); | |
165 |
|
165 | |||
166 |
this.events.on('status_ |
|
166 | this.events.on('status_dead.Kernel',function () { | |
|
167 | that.save_widget.update_document_title(); | |||
|
168 | knw.danger("Dead kernel"); | |||
|
169 | $kernel_ind_icon.attr('class','kernel_dead_icon').attr('title','Kernel Dead'); | |||
|
170 | }); | |||
|
171 | ||||
|
172 | this.events.on('status_dead.Kernel',function () { | |||
167 | var msg = 'The kernel has died, and the automatic restart has failed.' + |
|
173 | var msg = 'The kernel has died, and the automatic restart has failed.' + | |
168 | ' It is possible the kernel cannot be restarted.' + |
|
174 | ' It is possible the kernel cannot be restarted.' + | |
169 | ' If you are not able to restart the kernel, you will still be able to save' + |
|
175 | ' If you are not able to restart the kernel, you will still be able to save' + | |
@@ -178,10 +184,7 define([ | |||||
178 | buttons : { |
|
184 | buttons : { | |
179 | "Manual Restart": { |
|
185 | "Manual Restart": { | |
180 | class: "btn-danger", |
|
186 | class: "btn-danger", | |
181 |
click: |
|
187 | click: that.notebook.kernel.restart | |
182 | that.events.trigger('status_restarting.Kernel'); |
|
|||
183 | that.notebook.start_kernel(); |
|
|||
184 | } |
|
|||
185 | }, |
|
188 | }, | |
186 | "Don't restart": {} |
|
189 | "Don't restart": {} | |
187 | } |
|
190 | } | |
@@ -229,45 +232,19 define([ | |||||
229 | knw.danger(short, undefined, showMsg); |
|
232 | knw.danger(short, undefined, showMsg); | |
230 | }); |
|
233 | }); | |
231 |
|
234 | |||
232 |
this.events.on('status_ |
|
235 | this.events.on('status_idle.Kernel',function () { | |
233 | var kernel = data.kernel; |
|
236 | that.save_widget.update_document_title(); | |
234 | var ws_url = data.ws_url; |
|
237 | $kernel_ind_icon.attr('class','kernel_idle_icon').attr('title','Kernel Idle'); | |
235 | var early = data.early; |
|
238 | }); | |
236 | var msg; |
|
|||
237 |
|
239 | |||
238 | $kernel_ind_icon |
|
240 | this.events.on('status_busy.Kernel',function () { | |
239 | .attr('class', 'kernel_disconnected_icon') |
|
241 | window.document.title='(Busy) '+window.document.title; | |
240 | .attr('title', 'No Connection to Kernel'); |
|
242 | $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); | |
241 |
|
||||
242 | if (!early) { |
|
|||
243 | knw.warning('Reconnecting'); |
|
|||
244 | setTimeout(function () { |
|
|||
245 | kernel.start_channels(); |
|
|||
246 | }, 5000); |
|
|||
247 | return; |
|
|||
248 | } |
|
|||
249 | console.log('WebSocket connection failed: ', ws_url); |
|
|||
250 | msg = "A WebSocket connection could not be established." + |
|
|||
251 | " You will NOT be able to run code. Check your" + |
|
|||
252 | " network connection or notebook server configuration."; |
|
|||
253 | dialog.modal({ |
|
|||
254 | title: "WebSocket connection failed", |
|
|||
255 | body: msg, |
|
|||
256 | keyboard_manager: that.keyboard_manager, |
|
|||
257 | notebook: that.notebook, |
|
|||
258 | buttons : { |
|
|||
259 | "OK": {}, |
|
|||
260 | "Reconnect": { |
|
|||
261 | click: function () { |
|
|||
262 | knw.warning('Reconnecting'); |
|
|||
263 | setTimeout(function () { |
|
|||
264 | kernel.start_channels(); |
|
|||
265 | }, 5000); |
|
|||
266 | } |
|
|||
267 | } |
|
|||
268 | } |
|
|||
269 | }); |
|
|||
270 | }); |
|
243 | }); | |
|
244 | ||||
|
245 | // Start the kernel indicator in the busy state, and send a kernel_info request. | |||
|
246 | // When the kernel_info reply arrives, the kernel is idle. | |||
|
247 | $kernel_ind_icon.attr('class','kernel_busy_icon').attr('title','Kernel Busy'); | |||
271 | }; |
|
248 | }; | |
272 |
|
249 | |||
273 | /** |
|
250 | /** |
@@ -176,6 +176,9 define([ | |||||
176 | * POST /api/kernels/[:kernel_id]/restart |
|
176 | * POST /api/kernels/[:kernel_id]/restart | |
177 | */ |
|
177 | */ | |
178 | Kernel.prototype.restart = function (success, error) { |
|
178 | Kernel.prototype.restart = function (success, error) { | |
|
179 | this.events.trigger('status_restarting.Kernel', {kernel: this}); | |||
|
180 | this.stop_channels(); | |||
|
181 | ||||
179 | var that = this; |
|
182 | var that = this; | |
180 | var on_success = function (data, status, xhr) { |
|
183 | var on_success = function (data, status, xhr) { | |
181 | that._kernel_started(data, status, xhr); |
|
184 | that._kernel_started(data, status, xhr); | |
@@ -195,6 +198,18 define([ | |||||
195 | }); |
|
198 | }); | |
196 | }; |
|
199 | }; | |
197 |
|
200 | |||
|
201 | /** | |||
|
202 | * Not actually a HTTP request, but useful function nonetheless | |||
|
203 | * for reconnecting to the kernel if the connection is somehow lost | |||
|
204 | */ | |||
|
205 | Kernel.prototype.reconnect = function () { | |||
|
206 | this.events.trigger('status_reconnecting.Kernel'); | |||
|
207 | var that = this; | |||
|
208 | setTimeout(function () { | |||
|
209 | that.start_channels(); | |||
|
210 | }, 5000); | |||
|
211 | }; | |||
|
212 | ||||
198 | Kernel.prototype._on_success = function (success) { |
|
213 | Kernel.prototype._on_success = function (success) { | |
199 | var that = this; |
|
214 | var that = this; | |
200 | return function (data, status, xhr) { |
|
215 | return function (data, status, xhr) { | |
@@ -224,9 +239,12 define([ | |||||
224 | this.start_channels(); |
|
239 | this.start_channels(); | |
225 | }; |
|
240 | }; | |
226 |
|
241 | |||
227 |
Kernel.prototype._kernel_ |
|
242 | Kernel.prototype._kernel_connected = function () { | |
228 | this.events.trigger('status_restarting.Kernel', {kernel: this}); |
|
243 | var that = this; | |
229 | this.stop_channels(); |
|
244 | this.events.trigger('status_connected.Kernel'); | |
|
245 | this.kernel_info(function () { | |||
|
246 | that.events.trigger('status_idle.Kernel'); | |||
|
247 | }); | |||
230 | }; |
|
248 | }; | |
231 |
|
249 | |||
232 | Kernel.prototype._kernel_dead = function () { |
|
250 | Kernel.prototype._kernel_dead = function () { | |
@@ -234,12 +252,6 define([ | |||||
234 | this.stop_channels(); |
|
252 | this.stop_channels(); | |
235 | }; |
|
253 | }; | |
236 |
|
254 | |||
237 | Kernel.prototype._ws_closed = function(ws_url, early) { |
|
|||
238 | this.stop_channels(); |
|
|||
239 | this.events.trigger('status_disconnected.Kernel', |
|
|||
240 | {ws_url: ws_url, kernel: this, early: early} |
|
|||
241 | ); |
|
|||
242 | }; |
|
|||
243 |
|
255 | |||
244 | /** |
|
256 | /** | |
245 | * Start the `shell`and `iopub` channels. |
|
257 | * Start the `shell`and `iopub` channels. | |
@@ -325,6 +337,17 define([ | |||||
325 | } |
|
337 | } | |
326 | }; |
|
338 | }; | |
327 |
|
339 | |||
|
340 | Kernel.prototype._ws_closed = function(ws_url, early) { | |||
|
341 | this.stop_channels(); | |||
|
342 | this.events.trigger('status_disconnected.Kernel'); | |||
|
343 | if (!early) { | |||
|
344 | this.reconnect(); | |||
|
345 | } else { | |||
|
346 | console.log('WebSocket connection failed: ', ws_url); | |||
|
347 | this.events.trigger('early_disconnect.Kernel', ws_url); | |||
|
348 | } | |||
|
349 | }; | |||
|
350 | ||||
328 | /** |
|
351 | /** | |
329 | * Stop the websocket channels. |
|
352 | * Stop the websocket channels. | |
330 | * @method stop_channels |
|
353 | * @method stop_channels |
@@ -50,7 +50,6 define([ | |||||
50 | Session.prototype.start = function (success, error) { |
|
50 | Session.prototype.start = function (success, error) { | |
51 | var that = this; |
|
51 | var that = this; | |
52 | var on_success = function (data, status, xhr) { |
|
52 | var on_success = function (data, status, xhr) { | |
53 | console.log("Session started: ", data.id); |
|
|||
54 | var kernel_service_url = utils.url_path_join(that.base_url, "api/kernels"); |
|
53 | var kernel_service_url = utils.url_path_join(that.base_url, "api/kernels"); | |
55 | that.kernel = new kernel.Kernel( |
|
54 | that.kernel = new kernel.Kernel( | |
56 | kernel_service_url, that.ws_url, that.notebook, |
|
55 | kernel_service_url, that.ws_url, that.notebook, |
General Comments 0
You need to be logged in to leave comments.
Login now