##// END OF EJS Templates
Merge pull request #6876 from minrk/falloff-reconnect...
Kyle Kelley -
r18747:b13ab53f merge
parent child Browse files
Show More
@@ -295,6 +295,9 b' define(['
295 this.element.find('#restart_kernel').click(function () {
295 this.element.find('#restart_kernel').click(function () {
296 that.notebook.restart_kernel();
296 that.notebook.restart_kernel();
297 });
297 });
298 this.element.find('#reconnect_kernel').click(function () {
299 that.notebook.kernel.reconnect();
300 });
298 // Help
301 // Help
299 if (this.tour) {
302 if (this.tour) {
300 this.element.find('#notebook_tour').click(function () {
303 this.element.find('#notebook_tour').click(function () {
@@ -132,6 +132,13 b' define(['
132 knw.warning("Connecting to kernel");
132 knw.warning("Connecting to kernel");
133 });
133 });
134
134
135 this.events.on('kernel_connection_dead.Kernel', function (evt, info) {
136 knw.danger("Not Connected", undefined, function () {
137 // schedule reconnect a short time in the future, don't reconnect immediately
138 setTimeout($.proxy(info.kernel.reconnect, info.kernel), 500);
139 }, {title: 'click to reconnect'});
140 });
141
135 this.events.on('kernel_connected.Kernel', function () {
142 this.events.on('kernel_connected.Kernel', function () {
136 knw.info("Connected", 500);
143 knw.info("Connected", 500);
137 });
144 });
@@ -66,6 +66,7 b' define(['
66
66
67 this._autorestart_attempt = 0;
67 this._autorestart_attempt = 0;
68 this._reconnect_attempt = 0;
68 this._reconnect_attempt = 0;
69 this.reconnect_limit = 7;
69 };
70 };
70
71
71 /**
72 /**
@@ -332,8 +333,15 b' define(['
332 * @function reconnect
333 * @function reconnect
333 */
334 */
334 Kernel.prototype.reconnect = function () {
335 Kernel.prototype.reconnect = function () {
335 this.events.trigger('kernel_reconnecting.Kernel', {kernel: this});
336 if (this.is_connected()) {
336 setTimeout($.proxy(this.start_channels, this), 3000);
337 return;
338 }
339 this._reconnect_attempt = this._reconnect_attempt + 1;
340 this.events.trigger('kernel_reconnecting.Kernel', {
341 kernel: this,
342 attempt: this._reconnect_attempt,
343 });
344 this.start_channels();
337 };
345 };
338
346
339 /**
347 /**
@@ -524,12 +532,27 b' define(['
524 this.events.trigger('kernel_disconnected.Kernel', {kernel: this});
532 this.events.trigger('kernel_disconnected.Kernel', {kernel: this});
525 if (error) {
533 if (error) {
526 console.log('WebSocket connection failed: ', ws_url);
534 console.log('WebSocket connection failed: ', ws_url);
527 this._reconnect_attempt = this._reconnect_attempt + 1;
528 this.events.trigger('kernel_connection_failed.Kernel', {kernel: this, ws_url: ws_url, attempt: this._reconnect_attempt});
535 this.events.trigger('kernel_connection_failed.Kernel', {kernel: this, ws_url: ws_url, attempt: this._reconnect_attempt});
529 }
536 }
530 this.reconnect();
537 this._schedule_reconnect();
531 };
538 };
532
539
540 Kernel.prototype._schedule_reconnect = function () {
541 // function to call when kernel connection is lost
542 // schedules reconnect, or fires 'connection_dead' if reconnect limit is hit
543 if (this._reconnect_attempt < this.reconnect_limit) {
544 var timeout = Math.pow(2, this._reconnect_attempt);
545 console.log("Connection lost, reconnecting in " + timeout + " seconds.");
546 setTimeout($.proxy(this.reconnect, this), 1e3 * timeout);
547 } else {
548 this.events.trigger('kernel_connection_dead.Kernel', {
549 kernel: this,
550 reconnect_attempt: this._reconnect_attempt,
551 });
552 console.log("Failed to reconnect, giving up.");
553 }
554 };
555
533 /**
556 /**
534 * Close the websocket channels. After successful close, the value
557 * Close the websocket channels. After successful close, the value
535 * in `this.channels[channel_name]` will be null.
558 * in `this.channels[channel_name]` will be null.
@@ -230,10 +230,16 b' class="notebook_app"'
230 <ul id="kernel_menu" class="dropdown-menu">
230 <ul id="kernel_menu" class="dropdown-menu">
231 <li id="int_kernel"
231 <li id="int_kernel"
232 title="Send KeyboardInterrupt (CTRL-C) to the Kernel">
232 title="Send KeyboardInterrupt (CTRL-C) to the Kernel">
233 <a href="#">Interrupt</a></li>
233 <a href="#">Interrupt</a>
234 </li>
234 <li id="restart_kernel"
235 <li id="restart_kernel"
235 title="Restart the Kernel">
236 title="Restart the Kernel">
236 <a href="#">Restart</a></li>
237 <a href="#">Restart</a>
238 </li>
239 <li id="reconnect_kernel"
240 title="Reconnect to the Kernel">
241 <a href="#">Reconnect</a>
242 </li>
237 <li class="divider"></li>
243 <li class="divider"></li>
238 <li id="menu-change-kernel" class="dropdown-submenu">
244 <li id="menu-change-kernel" class="dropdown-submenu">
239 <a href="#">Change kernel</a>
245 <a href="#">Change kernel</a>
@@ -257,7 +257,11 b' casper.notebook_test(function () {'
257 'ws_closed_error',
257 'ws_closed_error',
258 [
258 [
259 'kernel_disconnected.Kernel',
259 'kernel_disconnected.Kernel',
260 'kernel_connection_failed.Kernel'
260 'kernel_connection_failed.Kernel',
261 'kernel_reconnecting.Kernel',
262 'kernel_connected.Kernel',
263 'kernel_busy.Kernel',
264 'kernel_idle.Kernel'
261 ],
265 ],
262 function () {
266 function () {
263 this.thenEvaluate(function () {
267 this.thenEvaluate(function () {
@@ -265,6 +269,8 b' casper.notebook_test(function () {'
265 });
269 });
266 }
270 }
267 );
271 );
272 // wait for any last idle/busy messages to be handled
273 this.wait_for_kernel_ready();
268
274
269 // start the kernel back up
275 // start the kernel back up
270 this.thenEvaluate(function () {
276 this.thenEvaluate(function () {
General Comments 0
You need to be logged in to leave comments. Login now