Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

philippjfr
Copy link
Member

The throttling/debouncing behavior behind stream callbacks seems to have regressed at some point, such that a datashaded HoloViews plot using PlotSize and RangeXY streams seems to generate a ton of events. This PR reimplements a debouncing approach that actually works. For now I've hardcoded the debounce timeout to 100ms, which is the value we use for notebook event debouncing.

@philippjfr philippjfr changed the title Add debounce support to PlotSize and RangeXY bokeh callbacks enh: Add debounce support to PlotSize and RangeXY bokeh callbacks Aug 26, 2025
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

❌ Patch coverage is 16.66667% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.67%. Comparing base (d68d810) to head (6055e50).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
holoviews/plotting/bokeh/callbacks.py 16.66% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6672      +/-   ##
==========================================
- Coverage   88.96%   87.67%   -1.29%     
==========================================
  Files         328      328              
  Lines       70221    70235      +14     
==========================================
- Hits        62473    61580     -893     
- Misses       7748     8655     +907     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if not self._active and self.plot.document:
self._active = True
self._set_busy(True)
await self.process_on_change()
state.execute(self.process_on_change)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change (and likewise for on_event) seems to be the reason why things fails. Getting _curdoc_locked RuntimeErorr when running locally with -s

ERROR    tornado.application:ioloop.py:778 Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOLoop object at 0x7f7038dd8980>>, <Task finished name='Task-117' coro=<Callback.process_on_event() done, defined at /home/shh/projects/holoviz/repos/holoviews/holoviews/plotting/bokeh/callbacks.py:344> exception=RuntimeError('_pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes')>)
Traceback (most recent call last):
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/tornado/ioloop.py", line 758, in _run_callback
    ret = callback()
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/tornado/ioloop.py", line 782, in _discard_future_result
    future.result()
    ~~~~~~~~~~~~~^^
  File "/home/shh/projects/holoviz/repos/holoviews/holoviews/plotting/bokeh/callbacks.py", line 374, in process_on_event
    await self.on_msg(msg)
  File "/home/shh/projects/holoviz/repos/holoviews/holoviews/plotting/bokeh/callbacks.py", line 728, in on_msg
    await self._process_selection_event()
  File "/home/shh/projects/holoviz/repos/holoviews/holoviews/plotting/bokeh/callbacks.py", line 768, in _process_selection_event
    self._panel.stylesheets = [
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/core/has_props.py", line 337, in __setattr__
    return super().__setattr__(name, value)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/core/property/descriptors.py", line 332, in __set__
    self._set(obj, old, value, setter=setter)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/core/property/descriptors.py", line 614, in _set
    self._trigger(obj, old, value, hint=hint, setter=setter)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/core/property/descriptors.py", line 692, in _trigger
    obj.trigger(self.name, old, value, hint, setter)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/model/model.py", line 583, in trigger
    super().trigger(descriptor.name, old, new, hint=hint, setter=setter)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/util/callback_manager.py", line 177, in trigger
    self.document.callbacks.notify_change(cast(Model, self), attr, old, new, hint, setter, invoke)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 251, in notify_change
    self.trigger_on_change(event)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 423, in trigger_on_change
    invoke_with_curdoc(doc, invoke_callbacks)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 453, in invoke_with_curdoc
    return f()
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 422, in invoke_callbacks
    cb(event)
    ~~^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/document/callbacks.py", line 278, in <lambda>
    self._change_callbacks[receiver] = lambda event: event.dispatch(receiver)
                                                     ~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/document/events.py", line 352, in dispatch
    super().dispatch(receiver)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/document/events.py", line 218, in dispatch
    cast(DocumentPatchedMixin, receiver)._document_patched(self)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/bokeh/server/session.py", line 244, in _document_patched
    raise RuntimeError("_pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes")
RuntimeError: _pending_writes should be non-None when we have a document lock, and we should have the lock when the document changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants