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 | |
@@ -48,6 +44,9 b' var IPython = (function (IPython) {' | |||||
48 | this.init_iopub_handlers(); |
|
44 | this.init_iopub_handlers(); | |
49 | this.comm_manager = new IPython.CommManager(this); |
|
45 | this.comm_manager = new IPython.CommManager(this); | |
50 | this.widget_manager = new IPython.WidgetManager(this.comm_manager); |
|
46 | this.widget_manager = new IPython.WidgetManager(this.comm_manager); | |
|
47 | ||||
|
48 | this.last_msg_id = null; | |||
|
49 | this.last_msg_callbacks = {}; | |||
51 | }; |
|
50 | }; | |
52 |
|
51 | |||
53 |
|
52 | |||
@@ -427,7 +426,11 b' var IPython = (function (IPython) {' | |||||
427 |
|
426 | |||
428 | Kernel.prototype.get_callbacks_for_msg = function (msg_id) { |
|
427 | Kernel.prototype.get_callbacks_for_msg = function (msg_id) { | |
429 | // get callbacks for a specific message |
|
428 | // get callbacks for a specific message | |
430 | return this._msg_callbacks[msg_id]; |
|
429 | if (msg_id == this.last_msg_id) { | |
|
430 | return this.last_msg_callbacks; | |||
|
431 | } else { | |||
|
432 | return this._msg_callbacks[msg_id]; | |||
|
433 | } | |||
431 | }; |
|
434 | }; | |
432 |
|
435 | |||
433 |
|
436 | |||
@@ -437,6 +440,26 b' var IPython = (function (IPython) {' | |||||
437 | } |
|
440 | } | |
438 | }; |
|
441 | }; | |
439 |
|
442 | |||
|
443 | Kernel.prototype._finish_shell = function (msg_id) { | |||
|
444 | var callbacks = this._msg_callbacks[msg_id]; | |||
|
445 | if (callbacks !== undefined) { | |||
|
446 | callbacks.shell_done = true; | |||
|
447 | if (callbacks.iopub_done) { | |||
|
448 | this.clear_callbacks_for_msg(msg_id); | |||
|
449 | } | |||
|
450 | } | |||
|
451 | }; | |||
|
452 | ||||
|
453 | Kernel.prototype._finish_iopub = function (msg_id) { | |||
|
454 | var callbacks = this._msg_callbacks[msg_id]; | |||
|
455 | if (callbacks !== undefined) { | |||
|
456 | callbacks.iopub_done = true; | |||
|
457 | if (!callbacks.shell_done) { | |||
|
458 | this.clear_callbacks_for_msg(msg_id); | |||
|
459 | } | |||
|
460 | } | |||
|
461 | }; | |||
|
462 | ||||
440 | /* Set callbacks for a particular message. |
|
463 | /* Set callbacks for a particular message. | |
441 | * Callbacks should be a struct of the following form: |
|
464 | * Callbacks should be a struct of the following form: | |
442 | * shell : { |
|
465 | * shell : { | |
@@ -445,13 +468,17 b' var IPython = (function (IPython) {' | |||||
445 |
|
468 | |||
446 | */ |
|
469 | */ | |
447 | Kernel.prototype.set_callbacks_for_msg = function (msg_id, callbacks) { |
|
470 | Kernel.prototype.set_callbacks_for_msg = function (msg_id, callbacks) { | |
|
471 | this.last_msg_id = msg_id; | |||
448 | if (callbacks) { |
|
472 | if (callbacks) { | |
449 | // shallow-copy mapping, because we will modify it at the top level |
|
473 | // shallow-copy mapping, because we will modify it at the top level | |
450 | var cbcopy = this._msg_callbacks[msg_id] = {}; |
|
474 | var cbcopy = this._msg_callbacks[msg_id] = this.last_msg_callbacks = {}; | |
451 | cbcopy.shell = callbacks.shell; |
|
475 | cbcopy.shell = callbacks.shell; | |
452 | cbcopy.iopub = callbacks.iopub; |
|
476 | cbcopy.iopub = callbacks.iopub; | |
453 | cbcopy.input = callbacks.input; |
|
477 | cbcopy.input = callbacks.input; | |
454 | this._msg_callbacks[msg_id] = cbcopy; |
|
478 | cbcopy.shell_done = (!callbacks.shell); | |
|
479 | cbcopy.iopub_done = (!callbacks.iopub); | |||
|
480 | } else { | |||
|
481 | this.last_msg_callbacks = {}; | |||
455 | } |
|
482 | } | |
456 | }; |
|
483 | }; | |
457 |
|
484 | |||
@@ -468,12 +495,8 b' var IPython = (function (IPython) {' | |||||
468 | } |
|
495 | } | |
469 | var shell_callbacks = callbacks.shell; |
|
496 | var shell_callbacks = callbacks.shell; | |
470 |
|
497 | |||
471 |
// |
|
498 | // signal that shell callbacks are done | |
472 | delete callbacks.shell; |
|
499 | this._finish_shell(parent_id); | |
473 | delete callbacks.input; |
|
|||
474 | if (!callbacks.iopub) { |
|
|||
475 | this.clear_callbacks_for_msg(parent_id); |
|
|||
476 | } |
|
|||
477 |
|
500 | |||
478 | if (shell_callbacks.reply !== undefined) { |
|
501 | if (shell_callbacks.reply !== undefined) { | |
479 | shell_callbacks.reply(reply); |
|
502 | shell_callbacks.reply(reply); | |
@@ -514,14 +537,11 b' var IPython = (function (IPython) {' | |||||
514 | if (execution_state === 'busy') { |
|
537 | if (execution_state === 'busy') { | |
515 | $([IPython.events]).trigger('status_busy.Kernel', {kernel: this}); |
|
538 | $([IPython.events]).trigger('status_busy.Kernel', {kernel: this}); | |
516 | } else if (execution_state === 'idle') { |
|
539 | } else if (execution_state === 'idle') { | |
517 | // clear callbacks on idle, there can be no more |
|
540 | // signal that iopub callbacks are (probably) done | |
518 | if (callbacks !== undefined) { |
|
541 | // async output may still arrive, | |
519 | delete callbacks.iopub; |
|
542 | // but only for the most recent request | |
520 | delete callbacks.input; |
|
543 | this._finish_iopub(parent_id); | |
521 | if (!callbacks.shell) { |
|
544 | ||
522 | this.clear_callbacks_for_msg(parent_id); |
|
|||
523 | } |
|
|||
524 | } |
|
|||
525 | // trigger status_idle event |
|
545 | // trigger status_idle event | |
526 | $([IPython.events]).trigger('status_idle.Kernel', {kernel: this}); |
|
546 | $([IPython.events]).trigger('status_idle.Kernel', {kernel: this}); | |
527 | } else if (execution_state === 'restarting') { |
|
547 | } else if (execution_state === 'restarting') { |
General Comments 0
You need to be logged in to leave comments.
Login now