##// END OF EJS Templates
Merge pull request #5668 from minrk/async-output...
Min RK -
r16557:2a61a250 merge
parent child Browse files
Show More
@@ -1,9 +1,5 b''
1 //----------------------------------------------------------------------------
1 // Copyright (c) IPython Development Team.
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Distributed under the terms of the Modified BSD License.
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
7
3
8 //============================================================================
4 //============================================================================
9 // Kernel
5 // Kernel
@@ -49,6 +45,9 b' var IPython = (function (IPython) {'
49 this.init_iopub_handlers();
45 this.init_iopub_handlers();
50 this.comm_manager = new IPython.CommManager(this);
46 this.comm_manager = new IPython.CommManager(this);
51 this.widget_manager = new IPython.WidgetManager(this.comm_manager);
47 this.widget_manager = new IPython.WidgetManager(this.comm_manager);
48
49 this.last_msg_id = null;
50 this.last_msg_callbacks = {};
52 };
51 };
53
52
54
53
@@ -429,7 +428,11 b' var IPython = (function (IPython) {'
429
428
430 Kernel.prototype.get_callbacks_for_msg = function (msg_id) {
429 Kernel.prototype.get_callbacks_for_msg = function (msg_id) {
431 // get callbacks for a specific message
430 // get callbacks for a specific message
431 if (msg_id == this.last_msg_id) {
432 return this.last_msg_callbacks;
433 } else {
432 return this._msg_callbacks[msg_id];
434 return this._msg_callbacks[msg_id];
435 }
433 };
436 };
434
437
435
438
@@ -439,6 +442,26 b' var IPython = (function (IPython) {'
439 }
442 }
440 };
443 };
441
444
445 Kernel.prototype._finish_shell = function (msg_id) {
446 var callbacks = this._msg_callbacks[msg_id];
447 if (callbacks !== undefined) {
448 callbacks.shell_done = true;
449 if (callbacks.iopub_done) {
450 this.clear_callbacks_for_msg(msg_id);
451 }
452 }
453 };
454
455 Kernel.prototype._finish_iopub = function (msg_id) {
456 var callbacks = this._msg_callbacks[msg_id];
457 if (callbacks !== undefined) {
458 callbacks.iopub_done = true;
459 if (!callbacks.shell_done) {
460 this.clear_callbacks_for_msg(msg_id);
461 }
462 }
463 };
464
442 /* Set callbacks for a particular message.
465 /* Set callbacks for a particular message.
443 * Callbacks should be a struct of the following form:
466 * Callbacks should be a struct of the following form:
444 * shell : {
467 * shell : {
@@ -447,13 +470,17 b' var IPython = (function (IPython) {'
447
470
448 */
471 */
449 Kernel.prototype.set_callbacks_for_msg = function (msg_id, callbacks) {
472 Kernel.prototype.set_callbacks_for_msg = function (msg_id, callbacks) {
473 this.last_msg_id = msg_id;
450 if (callbacks) {
474 if (callbacks) {
451 // shallow-copy mapping, because we will modify it at the top level
475 // shallow-copy mapping, because we will modify it at the top level
452 var cbcopy = this._msg_callbacks[msg_id] = {};
476 var cbcopy = this._msg_callbacks[msg_id] = this.last_msg_callbacks = {};
453 cbcopy.shell = callbacks.shell;
477 cbcopy.shell = callbacks.shell;
454 cbcopy.iopub = callbacks.iopub;
478 cbcopy.iopub = callbacks.iopub;
455 cbcopy.input = callbacks.input;
479 cbcopy.input = callbacks.input;
456 this._msg_callbacks[msg_id] = cbcopy;
480 cbcopy.shell_done = (!callbacks.shell);
481 cbcopy.iopub_done = (!callbacks.iopub);
482 } else {
483 this.last_msg_callbacks = {};
457 }
484 }
458 };
485 };
459
486
@@ -470,12 +497,8 b' var IPython = (function (IPython) {'
470 }
497 }
471 var shell_callbacks = callbacks.shell;
498 var shell_callbacks = callbacks.shell;
472
499
473 // clear callbacks on shell
500 // signal that shell callbacks are done
474 delete callbacks.shell;
501 this._finish_shell(parent_id);
475 delete callbacks.input;
476 if (!callbacks.iopub) {
477 this.clear_callbacks_for_msg(parent_id);
478 }
479
502
480 if (shell_callbacks.reply !== undefined) {
503 if (shell_callbacks.reply !== undefined) {
481 shell_callbacks.reply(reply);
504 shell_callbacks.reply(reply);
@@ -516,14 +539,11 b' var IPython = (function (IPython) {'
516 if (execution_state === 'busy') {
539 if (execution_state === 'busy') {
517 $([IPython.events]).trigger('status_busy.Kernel', {kernel: this});
540 $([IPython.events]).trigger('status_busy.Kernel', {kernel: this});
518 } else if (execution_state === 'idle') {
541 } else if (execution_state === 'idle') {
519 // clear callbacks on idle, there can be no more
542 // signal that iopub callbacks are (probably) done
520 if (callbacks !== undefined) {
543 // async output may still arrive,
521 delete callbacks.iopub;
544 // but only for the most recent request
522 delete callbacks.input;
545 this._finish_iopub(parent_id);
523 if (!callbacks.shell) {
546
524 this.clear_callbacks_for_msg(parent_id);
525 }
526 }
527 // trigger status_idle event
547 // trigger status_idle event
528 $([IPython.events]).trigger('status_idle.Kernel', {kernel: this});
548 $([IPython.events]).trigger('status_idle.Kernel', {kernel: this});
529 } else if (execution_state === 'restarting') {
549 } else if (execution_state === 'restarting') {
General Comments 0
You need to be logged in to leave comments. Login now