Skip to content

Commit

Permalink
Merge pull request #962 from ioam/stream_callback_timeout
Browse files Browse the repository at this point in the history
Add short timeout to bokeh stream callbacks
  • Loading branch information
jlstevens authored Oct 31, 2016
2 parents d74a10f + 3e6b2ec commit beb27db
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions holoviews/plotting/bokeh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,22 @@ class Callback(object):
HoloViewsWidget.comm_state["{comms_target}"] = comm_state
}}
function trigger() {{
if (comm_state.event != undefined) {{
comm.send(comm_state.event);
}}
comm_state.event = undefined;
}}
timeout = comm_state.timeout + {timeout};
if ((window.Jupyter == undefined) | (Jupyter.notebook.kernel == undefined)) {{
}} else if ((comm_state.blocked && (Date.now() < timeout))) {{
comm_state.event = argstring;
}} else {{
comm.send(argstring);
comm_state.event = argstring;
setTimeout(trigger, {debounce});
comm_state.blocked = true;
comm_state.timeout = Date.now();
comm_state.timeout = Date.now()+{debounce};
}}
"""

Expand All @@ -134,6 +142,9 @@ class Callback(object):
# Timeout if a comm message is swallowed
timeout = 20000

# Timeout before the first event is processed
debounce = 20

_callbacks = {}

def __init__(self, plot, streams, source, **params):
Expand Down Expand Up @@ -182,7 +193,8 @@ def set_customjs(self, handle):

# Generate callback JS code to get all the requested data
self_callback = self.js_callback.format(comms_target=self.comm.target,
timeout=self.timeout)
timeout=self.timeout,
debounce=self.debounce)
attributes = attributes_js(self.attributes)
code = 'var data = {};\n' + attributes + self.code + self_callback

Expand Down

0 comments on commit beb27db

Please sign in to comment.