##// END OF EJS Templates
Refactoring WebSocket connection failure logic....
Brian E. Granger -
Show More
@@ -111,35 +111,10 var IPython = (function (IPython) {
111
111
112
112
113 Kernel.prototype._websocket_closed = function(ws_url, early){
113 Kernel.prototype._websocket_closed = function(ws_url, early) {
114 var msg;
114 this.stop_channels();
115 var parent_item = $('body');
115 $([IPython.events]).trigger('websocket_closed.Kernel',
116 if (early) {
116 {ws_url: ws_url, kernel: this, early: early}
117 msg = "Websocket connection to " + ws_url + " could not be established." +
117 );
118 " You will NOT be able to run code." +
119 " Your browser may not be compatible with the websocket version in the server," +
120 " or if the url does not look right, there could be an error in the" +
121 " server's configuration.";
122 } else {
123 IPython.notification_area.widget('kernel').set_message('Reconnecting Websockets', 1000);
124 this.start_channels();
125 return;
126 }
127 var dialog = $('<div/>');
128 dialog.html(msg);
129 parent_item.append(dialog);
130 dialog.dialog({
131 resizable: false,
132 modal: true,
133 title: "Websocket closed",
134 closeText: "",
135 close: function(event, ui) {$(this).dialog('destroy').remove();},
136 buttons : {
137 "OK": function () {
138 $(this).dialog('close');
139 }
140 }
141 });
142
143 };
118 };
144
119
145 /**
120 /**
@@ -152,7 +127,7 var IPython = (function (IPython) {
152 var that = this;
127 var that = this;
153 this.stop_channels();
128 this.stop_channels();
154 var ws_url = this.ws_url + this.kernel_url;
129 var ws_url = this.ws_url + this.kernel_url;
155 console.log("Starting WS:", ws_url);
130 console.log("Starting WebSockets:", ws_url);
156 this.shell_channel = new this.WebSocket(ws_url + "/shell");
131 this.shell_channel = new this.WebSocket(ws_url + "/shell");
157 this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
132 this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
158 send_cookie = function(){
133 send_cookie = function(){
@@ -183,8 +158,12 var IPython = (function (IPython) {
183 this.iopub_channel.onclose = ws_closed_early;
158 this.iopub_channel.onclose = ws_closed_early;
184 // switch from early-close to late-close message after 1s
159 // switch from early-close to late-close message after 1s
185 setTimeout(function(){
160 setTimeout(function() {
161 if (that.shell_channel !== null) {
186 that.shell_channel.onclose = ws_closed_late;
162 that.shell_channel.onclose = ws_closed_late;
163 }
164 if (that.iopub_channel !== null) {
187 that.iopub_channel.onclose = ws_closed_late;
165 that.iopub_channel.onclose = ws_closed_late;
166 }
188 }, 1000);
167 }, 1000);
189 };
168 };
190
169
@@ -93,25 +93,72 var IPython = (function (IPython) {
93
93
94 $([IPython.events]).on('status_dead.Kernel',function () {
94 $([IPython.events]).on('status_dead.Kernel',function () {
95 var dialog = $('<div/>');
95 var dialog = $('<div/>');
96 dialog.html('The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.');
96 dialog.html('The kernel has died, would you like to restart it?' +
97 ' If you do not restart the kernel, you will be able to save' +
98 ' the notebook, but running code will not work until the notebook' +
99 ' is reopened.'
100 );
97 $(document).append(dialog);
101 $(document).append(dialog);
98 dialog.dialog({
102 dialog.dialog({
99 resizable: false,
103 resizable: false,
100 modal: true,
104 modal: true,
101 title: "Dead kernel",
105 title: "Dead kernel",
106 close: function(event, ui) {$(this).dialog('destroy').remove();},
102 buttons : {
107 buttons : {
103 "Restart": function () {
108 "Restart": function () {
104 $([IPython.events]).trigger('status_restarting.Kernel');
109 $([IPython.events]).trigger('status_restarting.Kernel');
105 IPython.notebook.start_kernel();
110 IPython.notebook.start_kernel();
106 $(this).dialog('close');
111 $(this).dialog('close');
107 },
112 },
108 "Continue running": function () {
113 "Don't restart": function () {
109 $(this).dialog('close');
114 $(this).dialog('close');
110 }
115 }
111 }
116 }
112 });
117 });
113 });
118 });
114
119
120 $([IPython.events]).on('websocket_closed.Kernel', function (event, data) {
121 var kernel = data.kernel;
122 var ws_url = data.ws_url;
123 var early = data.early;
124 var msg;
125 console.log(early);
126 if (!early) {
127 knw.set_message('Reconnecting WebSockets', 1000);
128 setTimeout(function () {
129 kernel.start_channels();
130 }, 5000);
131 return;
132 }
133 console.log('WebSocket connection failed: ', ws_url)
134 msg = "A WebSocket connection to could not be established." +
135 " You will NOT be able to run code. Check your" +
136 " network connection or notebook server configuration.";
137 var dialog = $('<div/>');
138 dialog.html(msg);
139 $(document).append(dialog);
140 dialog.dialog({
141 resizable: false,
142 modal: true,
143 title: "WebSocket connection failed",
144 closeText: "",
145 close: function(event, ui) {$(this).dialog('destroy').remove();},
146 buttons : {
147 "OK": function () {
148 $(this).dialog('close');
149 },
150 "Reconnect": function () {
151 knw.set_message('Reconnecting WebSockets', 1000);
152 setTimeout(function () {
153 kernel.start_channels();
154 }, 5000);
155 $(this).dialog('close');
156 }
157 }
158 });
159 });
160
161
115 var nnw = this.new_notification_widget('notebook');
162 var nnw = this.new_notification_widget('notebook');
116
163
117 // Notebook events
164 // Notebook events
General Comments 0
You need to be logged in to leave comments. Login now