##// END OF EJS Templates
Move js donc into function themselves....
Matthias Bussonnier -
Show More
@@ -284,6 +284,7 define([
284 284 });
285 285 };
286 286
287 Kernel.prototype.restart = function (success, error) {
287 288 /**
288 289 * POST /api/kernels/[:kernel_id]/restart
289 290 *
@@ -293,7 +294,6 define([
293 294 * @param {function} [success] - function executed on ajax success
294 295 * @param {function} [error] - functon executed on ajax error
295 296 */
296 Kernel.prototype.restart = function (success, error) {
297 297 this.events.trigger('kernel_restarting.Kernel', {kernel: this});
298 298 this.stop_channels();
299 299
@@ -325,6 +325,7 define([
325 325 });
326 326 };
327 327
328 Kernel.prototype.reconnect = function () {
328 329 /**
329 330 * Reconnect to a disconnected kernel. This is not actually a
330 331 * standard HTTP request, but useful function nonetheless for
@@ -332,7 +333,6 define([
332 333 *
333 334 * @function reconnect
334 335 */
335 Kernel.prototype.reconnect = function () {
336 336 if (this.is_connected()) {
337 337 return;
338 338 }
@@ -344,6 +344,7 define([
344 344 this.start_channels();
345 345 };
346 346
347 Kernel.prototype._on_success = function (success) {
347 348 /**
348 349 * Handle a successful AJAX request by updating the kernel id and
349 350 * name from the response, and then optionally calling a provided
@@ -352,7 +353,6 define([
352 353 * @function _on_success
353 354 * @param {function} success - callback
354 355 */
355 Kernel.prototype._on_success = function (success) {
356 356 var that = this;
357 357 return function (data, status, xhr) {
358 358 if (data) {
@@ -366,6 +366,7 define([
366 366 };
367 367 };
368 368
369 Kernel.prototype._on_error = function (error) {
369 370 /**
370 371 * Handle a failed AJAX request by logging the error message, and
371 372 * then optionally calling a provided callback.
@@ -373,7 +374,6 define([
373 374 * @function _on_error
374 375 * @param {function} error - callback
375 376 */
376 Kernel.prototype._on_error = function (error) {
377 377 return function (xhr, status, err) {
378 378 utils.log_ajax_error(xhr, status, err);
379 379 if (error) {
@@ -382,6 +382,7 define([
382 382 };
383 383 };
384 384
385 Kernel.prototype._kernel_created = function (data) {
385 386 /**
386 387 * Perform necessary tasks once the kernel has been started,
387 388 * including actually connecting to the kernel.
@@ -389,12 +390,12 define([
389 390 * @function _kernel_created
390 391 * @param {Object} data - information about the kernel including id
391 392 */
392 Kernel.prototype._kernel_created = function (data) {
393 393 this.id = data.id;
394 394 this.kernel_url = utils.url_join_encode(this.kernel_service_url, this.id);
395 395 this.start_channels();
396 396 };
397 397
398 Kernel.prototype._kernel_connected = function () {
398 399 /**
399 400 * Perform necessary tasks once the connection to the kernel has
400 401 * been established. This includes requesting information about
@@ -402,7 +403,6 define([
402 403 *
403 404 * @function _kernel_connected
404 405 */
405 Kernel.prototype._kernel_connected = function () {
406 406 this.events.trigger('kernel_connected.Kernel', {kernel: this});
407 407 this.events.trigger('kernel_starting.Kernel', {kernel: this});
408 408 // get kernel info so we know what state the kernel is in
@@ -413,6 +413,7 define([
413 413 });
414 414 };
415 415
416 Kernel.prototype._kernel_dead = function () {
416 417 /**
417 418 * Perform necessary tasks after the kernel has died. This closing
418 419 * communication channels to the kernel if they are still somehow
@@ -420,17 +421,16 define([
420 421 *
421 422 * @function _kernel_dead
422 423 */
423 Kernel.prototype._kernel_dead = function () {
424 424 this.stop_channels();
425 425 };
426 426
427 Kernel.prototype.start_channels = function () {
427 428 /**
428 429 * Start the `shell`and `iopub` channels.
429 430 * Will stop and restart them if they already exist.
430 431 *
431 432 * @function start_channels
432 433 */
433 Kernel.prototype.start_channels = function () {
434 434 var that = this;
435 435 this.stop_channels();
436 436 var ws_host_url = this.ws_url + this.kernel_url;
@@ -504,19 +504,20 define([
504 504 this.channels.stdin.onmessage = $.proxy(this._handle_input_request, this);
505 505 };
506 506
507 Kernel.prototype._ws_opened = function (evt) {
507 508 /**
508 509 * Handle a websocket entering the open state,
509 510 * signaling that the kernel is connected when all channels are open.
510 511 *
511 512 * @function _ws_opened
512 513 */
513 Kernel.prototype._ws_opened = function (evt) {
514 514 if (this.is_connected()) {
515 515 // all events ready, trigger started event.
516 516 this._kernel_connected();
517 517 }
518 518 };
519 519
520 Kernel.prototype._ws_closed = function(ws_url, error) {
520 521 /**
521 522 * Handle a websocket entering the closed state. This closes the
522 523 * other communication channels if they are open. If the websocket
@@ -526,7 +527,6 define([
526 527 * @param {string} ws_url - the websocket url
527 528 * @param {bool} error - whether the connection was closed due to an error
528 529 */
529 Kernel.prototype._ws_closed = function(ws_url, error) {
530 530 this.stop_channels();
531 531
532 532 this.events.trigger('kernel_disconnected.Kernel', {kernel: this});
@@ -553,13 +553,13 define([
553 553 }
554 554 };
555 555
556 Kernel.prototype.stop_channels = function () {
556 557 /**
557 558 * Close the websocket channels. After successful close, the value
558 559 * in `this.channels[channel_name]` will be null.
559 560 *
560 561 * @function stop_channels
561 562 */
562 Kernel.prototype.stop_channels = function () {
563 563 var that = this;
564 564 var close = function (c) {
565 565 return function () {
@@ -580,6 +580,7 define([
580 580 }
581 581 };
582 582
583 Kernel.prototype.is_connected = function () {
583 584 /**
584 585 * Check whether there is a connection to the kernel. This
585 586 * function only returns true if all channel objects have been
@@ -588,7 +589,6 define([
588 589 * @function is_connected
589 590 * @returns {bool} - whether there is a connection
590 591 */
591 Kernel.prototype.is_connected = function () {
592 592 for (var c in this.channels) {
593 593 // if any channel is not ready, then we're not connected
594 594 if (this.channels[c] === null) {
@@ -601,6 +601,7 define([
601 601 return true;
602 602 };
603 603
604 Kernel.prototype.is_fully_disconnected = function () {
604 605 /**
605 606 * Check whether the connection to the kernel has been completely
606 607 * severed. This function only returns true if all channel objects
@@ -609,7 +610,6 define([
609 610 * @function is_fully_disconnected
610 611 * @returns {bool} - whether the kernel is fully disconnected
611 612 */
612 Kernel.prototype.is_fully_disconnected = function () {
613 613 for (var c in this.channels) {
614 614 if (this.channels[c] === null) {
615 615 return true;
@@ -618,12 +618,12 define([
618 618 return false;
619 619 };
620 620
621 Kernel.prototype.send_shell_message = function (msg_type, content, callbacks, metadata, buffers) {
621 622 /**
622 623 * Send a message on the Kernel's shell channel
623 624 *
624 625 * @function send_shell_message
625 626 */
626 Kernel.prototype.send_shell_message = function (msg_type, content, callbacks, metadata, buffers) {
627 627 if (!this.is_connected()) {
628 628 throw new Error("kernel is not connected");
629 629 }
@@ -633,6 +633,7 define([
633 633 return msg.header.msg_id;
634 634 };
635 635
636 Kernel.prototype.kernel_info = function (callback) {
636 637 /**
637 638 * Get kernel info
638 639 *
@@ -643,7 +644,6 define([
643 644 * The callback will be passed the complete `kernel_info_reply` message documented
644 645 * [here](http://ipython.org/ipython-doc/dev/development/messaging.html#kernel-info)
645 646 */
646 Kernel.prototype.kernel_info = function (callback) {
647 647 var callbacks;
648 648 if (callback) {
649 649 callbacks = { shell : { reply : callback } };
@@ -651,6 +651,7 define([
651 651 return this.send_shell_message("kernel_info_request", {}, callbacks);
652 652 };
653 653
654 Kernel.prototype.inspect = function (code, cursor_pos, callback) {
654 655 /**
655 656 * Get info on an object
656 657 *
@@ -663,7 +664,6 define([
663 664 * @param cursor_pos {integer}
664 665 * @param callback {function}
665 666 */
666 Kernel.prototype.inspect = function (code, cursor_pos, callback) {
667 667 var callbacks;
668 668 if (callback) {
669 669 callbacks = { shell : { reply : callback } };
@@ -677,6 +677,7 define([
677 677 return this.send_shell_message("inspect_request", content, callbacks);
678 678 };
679 679
680 Kernel.prototype.execute = function (code, callbacks, options) {
680 681 /**
681 682 * Execute given code into kernel, and pass result to callback.
682 683 *
@@ -726,7 +727,6 define([
726 727 * arugment. Payload handlers will be passed the corresponding
727 728 * payload and the execute_reply message.
728 729 */
729 Kernel.prototype.execute = function (code, callbacks, options) {
730 730 var content = {
731 731 code : code,
732 732 silent : true,
General Comments 0
You need to be logged in to leave comments. Login now