Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed throttling on bokeh server #2112

Merged
merged 1 commit into from Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions holoviews/plotting/bokeh/callbacks.py
Expand Up @@ -330,6 +330,11 @@ class ServerCallback(MessageCallback):
Stream(s) attached to the callback.
"""

def __init__(self, plot, streams, source, **params):
super(ServerCallback, self).__init__(plot, streams, source, **params)
self._active = False


@classmethod
def resolve_attr_spec(cls, spec, cb_obj, model=None):
"""
Expand Down Expand Up @@ -360,8 +365,9 @@ def on_change(self, attr, old, new):
value change at once rather than firing off multiple plot updates.
"""
self._queue.append((attr, old, new))
if self.process_on_change not in self.plot.document._session_callbacks:
if not self._active:
self.plot.document.add_timeout_callback(self.process_on_change, 50)
self._active = True


def on_event(self, event):
Expand All @@ -370,16 +376,18 @@ def on_event(self, event):
value change at once rather than firing off multiple plot updates.
"""
self._queue.append((event))
if self.process_on_event not in self.plot.document._session_callbacks:
if not self._active:
self.plot.document.add_timeout_callback(self.process_on_event, 50)

self._active = True

def process_on_event(self):
"""
Trigger callback change event and triggering corresponding streams.
"""
if not self._queue:
self._active = False
return
self._queue = []
# Get unique event types in the queue
events = list(OrderedDict([(event.event_name, event)
for event in self._queue]).values())
Expand All @@ -397,6 +405,7 @@ def process_on_event(self):

def process_on_change(self):
if not self._queue:
self._active = False
return
self._queue = []

Expand All @@ -419,7 +428,7 @@ def set_server_callback(self, handle):
"""
Set up on_change events for bokeh server interactions.
"""
if self.on_events and bokeh_version >= '0.12.5':
if self.on_events:
for event in self.on_events:
handle.on_event(event, self.on_event)
elif self.on_changes:
Expand Down
7 changes: 6 additions & 1 deletion holoviews/plotting/bokeh/widgets.py
Expand Up @@ -77,6 +77,7 @@ def __init__(self, plot, renderer=None, **params):
self.attach_callbacks()
self.state = self.init_layout()
self._queue = []
self._active = False


@classmethod
Expand Down Expand Up @@ -184,16 +185,20 @@ def attach_callbacks(self):

def on_change(self, dim, widget_type, attr, old, new):
self._queue.append((dim, widget_type, attr, old, new))
if self.update not in self.plot.document._session_callbacks:
if not self._active:
self.plot.document.add_timeout_callback(self.update, 50)
self._active = True


def update(self):
"""
Handle update events on bokeh server.
"""
if not self._queue:
self._active = False
return
self._queue = []

dim, widget_type, attr, old, new = self._queue[-1]
dim_label = dim.pprint_label

Expand Down