Skip to content

Commit

Permalink
Added comms_target ID to ACK message protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 5, 2017
1 parent 16e9f92 commit 9aa0a0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 10 additions & 4 deletions holoviews/plotting/bokeh/callbacks.py
Expand Up @@ -85,14 +85,20 @@ class Callback(object):
js_callback = """
function on_msg(msg){{
msg = JSON.parse(msg.content.data);
var comm = HoloViewsWidget.comms["{comms_target}"];
var comm_state = HoloViewsWidget.comm_state["{comms_target}"];
if ("comms_target" in msg) {{
comms_target = msg["comms_target"]
}} else {{
comms_target = "{comms_target}"
}}
var comm = HoloViewsWidget.comms[comms_target];
var comm_state = HoloViewsWidget.comm_state[comms_target];
if (comm_state.event) {{
comm.send(comm_state.event);
comm_state.blocked = true;
comm_state.timeout = Date.now()+{debounce};
}} else {{
comm_state.blocked = false;
}}
comm_state.timeout = Date.now();
comm_state.event = undefined;
if ((msg.msg_type == "Ready") && msg.content) {{
console.log("Python callback returned following output:", msg.content);
Expand All @@ -101,6 +107,7 @@ class Callback(object):
}}
}}
data['comms_target'] = "{comms_target}";
var argstring = JSON.stringify(data);
if ((window.Jupyter !== undefined) && (Jupyter.notebook.kernel !== undefined)) {{
var comm_manager = Jupyter.notebook.kernel.comm_manager;
Expand Down Expand Up @@ -181,7 +188,6 @@ def initialize(self):


def on_msg(self, msg):
msg = json.loads(msg)
for stream in self.streams:
ids = self.stream_handles[stream]
sanitized_msg = {}
Expand Down
10 changes: 6 additions & 4 deletions holoviews/plotting/comms.py
Expand Up @@ -114,11 +114,13 @@ def _handle_msg(self, msg):
if stdout:
stdout = '\n\t'+'\n\t'.join(stdout)
error = '\n'.join([stdout, error])
msg = {'msg_type': "Error", 'traceback': error}
reply = {'msg_type': "Error", 'traceback': error}
else:
stdout = '\n\t'+'\n\t'.join(stdout) if stdout else ''
msg = {'msg_type': "Ready", 'content': stdout}
self.comm.send(json.dumps(msg))
reply = {'msg_type': "Ready", 'content': stdout}
if 'comms_target' in msg:
reply['comms_target'] = msg.pop('comms_target', None)
self.comm.send(json.dumps(reply))


class JupyterComm(Comm):
Expand Down Expand Up @@ -154,7 +156,7 @@ def init(self):

@classmethod
def decode(cls, msg):
return msg['content']['data']
return json.loads(msg['content']['data'])


def send(self, data):
Expand Down

0 comments on commit 9aa0a0f

Please sign in to comment.