From 1c930b1b9c6a0427ff46e89edbf862632fa981ed Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 11 Oct 2016 11:54:50 +0200 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20clear=20callbacks=20for=20cell?= =?UTF-8?q?=20output=20until=20next=20execute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adds callbacks.clear_on_done bool flag for kernel callbacks. Default: true (current behavior) Setting to false means that the caller is taking responsibility for clearing callbacks. Use this in cells to only clear callbacks on the next execution, for better handling of async output. --- notebook/static/notebook/js/codecell.js | 3 ++- notebook/static/services/kernels/kernel.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/notebook/static/notebook/js/codecell.js b/notebook/static/notebook/js/codecell.js index 2fb7ceeea..435caa471 100644 --- a/notebook/static/notebook/js/codecell.js +++ b/notebook/static/notebook/js/codecell.js @@ -340,6 +340,7 @@ define([ CodeCell.prototype.get_callbacks = function () { var that = this; return { + clear_on_done: false, shell : { reply : $.proxy(this._handle_execute_reply, this), payload : { @@ -357,7 +358,7 @@ define([ that.output_area.handle_clear_output.apply(that.output_area, arguments); }, }, - input : $.proxy(this._handle_input_request, this) + input : $.proxy(this._handle_input_request, this), }; }; diff --git a/notebook/static/services/kernels/kernel.js b/notebook/static/services/kernels/kernel.js index 284892396..82f96acb1 100644 --- a/notebook/static/services/kernels/kernel.js +++ b/notebook/static/services/kernels/kernel.js @@ -726,6 +726,7 @@ define([ * @param callbacks.iopub.output {function} * @param callbacks.iopub.clear_output {function} * @param callbacks.input {function} + * @param callbacks.clear_on_done=true {Bolean} * @param {object} [options] * @param [options.silent=false] {Boolean} * @param [options.user_expressions=empty_dict] {Dict} @@ -864,7 +865,7 @@ define([ var callbacks = this._msg_callbacks[msg_id]; if (callbacks !== undefined) { callbacks.shell_done = true; - if (callbacks.iopub_done) { + if (callbacks.clear_on_done && callbacks.iopub_done) { this.clear_callbacks_for_msg(msg_id); } } @@ -877,7 +878,7 @@ define([ var callbacks = this._msg_callbacks[msg_id]; if (callbacks !== undefined) { callbacks.iopub_done = true; - if (callbacks.shell_done) { + if (callbacks.clear_on_done && callbacks.shell_done) { this.clear_callbacks_for_msg(msg_id); } } @@ -900,8 +901,13 @@ define([ cbcopy.shell = callbacks.shell; cbcopy.iopub = callbacks.iopub; cbcopy.input = callbacks.input; + cbcopy.clear_on_done = callbacks.clear_on_done; cbcopy.shell_done = (!callbacks.shell); cbcopy.iopub_done = (!callbacks.iopub); + if (callbacks.clear_on_done === undefined) { + // default to clear-on-done + cbcopy.clear_on_done = true; + } } else { this.last_msg_callbacks = {}; }