From b666345633d616fa9a8bd8b1a53881e7d831affe Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 22 Oct 2013 19:51:20 -0700 Subject: [PATCH] allow callbacks on status messages --- .../html/static/services/kernels/js/kernel.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index 0dcdf7bd8..9aa91aa2c 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -481,12 +481,22 @@ var IPython = (function (IPython) { Kernel.prototype._handle_status_message = function (msg) { var execution_state = msg.content.execution_state; + var parent_id = msg.parent_header.msg_id; + + // dispatch status msg callbacks, if any + var callbacks = this.get_callbacks_for_msg(parent_id); + if (callbacks && callbacks.iopub && callbacks.iopub.status) { + try { + callbacks.iopub.status(msg); + } catch (e) { + console.log("Exception in status msg handler", e); + } + } + if (execution_state === 'busy') { $([IPython.events]).trigger('status_busy.Kernel', {kernel: this}); } else if (execution_state === 'idle') { - // clear callbacks - var parent_id = msg.parent_header.msg_id; - var callbacks = this.get_callbacks_for_msg(parent_id); + // clear callbacks on idle, there can be no more if (callbacks !== undefined) { delete callbacks.iopub; delete callbacks.input; @@ -494,7 +504,7 @@ var IPython = (function (IPython) { this.clear_callbacks_for_msg(parent_id); } } - + // trigger status_idle event $([IPython.events]).trigger('status_idle.Kernel', {kernel: this}); } else if (execution_state === 'restarting') { // autorestarting is distinct from restarting,