diff --git a/lumen/pipeline.py b/lumen/pipeline.py index 357621e17..19948ac33 100644 --- a/lumen/pipeline.py +++ b/lumen/pipeline.py @@ -14,6 +14,7 @@ import tqdm # type: ignore from panel.io.document import unlocked +from panel.io.state import state as pn_state from panel.viewable import Viewer from panel.widgets import Widget from typing_extensions import Literal @@ -301,8 +302,12 @@ def _update_data(self, *events: param.parameterized.Event, force: bool = False): for f in self.filters+self.transforms+self.sql_transforms: f._sync_refs() - with unlocked(): - self.data = self._compute_data() + new_data = self._compute_data() + if pn_state._unblocked(pn_state.curdoc): + with unlocked(): + self.data = new_data + else: + self.data = new_data if state.config and state.config.on_update: pn.state.execute(partial(state.config.on_update, self)) self._stale = False diff --git a/lumen/util.py b/lumen/util.py index 2aa399fe5..c87948f15 100644 --- a/lumen/util.py +++ b/lumen/util.py @@ -7,7 +7,6 @@ import sys import unicodedata -from contextlib import contextmanager from functools import partial, wraps from logging import getLogger from subprocess import check_output @@ -20,8 +19,7 @@ from jinja2 import DebugUndefined, Environment, Undefined from packaging.version import Version from pandas.core.dtypes.dtypes import CategoricalDtype -from panel import state -from panel.io.document import unlocked +from panel.io.state import state log = getLogger(__name__) @@ -142,19 +140,19 @@ def _j_getshell(x): def _j_getheaders(x): if isinstance(x, Undefined): x = x._undefined_name - return pn.state.headers.get(x, '') + return state.headers.get(x, '') def _j_getcookies(x): if isinstance(x, Undefined): x = x._undefined_name - return pn.state.cookies.get(x, '') + return state.cookies.get(x, '') def _j_getoauth(x): if isinstance(x, Undefined): x = x._undefined_name - if pn.state.user_info is None: + if state.user_info is None: return '' - return pn.state.user_info.get(x, '') + return state.user_info.get(x, '') def expand_spec(pars, context={}, getenv=True, getshell=True, getheaders=True, getcookies=True, getoauth=True): @@ -308,14 +306,14 @@ def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: - from .state import state - if state.config and state.config.on_error: - pn.state.execute(partial(state.config.on_error, e)) + from .state import state as session_state + if session_state.config and session_state.config.on_error: + state.execute(partial(state.config.on_error, e)) if pn.config.notifications: log.error( f"{func.__qualname__!r} raised {type(e).__name__}: {e}" ) - pn.state.notifications.error(message.format(e=e)) + state.notifications.error(message.format(e=e)) else: raise e return wrapper @@ -325,28 +323,6 @@ def wrapper(*args, **kwargs): return decorator -@contextmanager -def immediate_dispatch(doc=None): - """ - Utility to trigger immediate dispatch of events even when Document - events are currently on hold. - """ - doc = doc or state.curdoc - - # Skip if not in a server context - if not doc or not doc._session_context: - yield - return - - old_events = doc.callbacks._held_events - hold = doc.callbacks._hold - doc.callbacks._held_events = [] - doc.callbacks.unhold() - with unlocked(): - yield - doc.callbacks._hold = hold - doc.callbacks._held_events = old_events - def slugify(value, allow_unicode=False) -> str: """ Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated diff --git a/lumen/views/base.py b/lumen/views/base.py index 50df8c102..647809dad 100644 --- a/lumen/views/base.py +++ b/lumen/views/base.py @@ -18,6 +18,7 @@ from bokeh.models import NumeralTickFormatter # type: ignore from packaging.version import Version +from panel.io.document import immediate_dispatch from panel.pane.base import PaneBase from panel.pane.perspective import ( THEMES as _PERSPECTIVE_THEMES, Plugin as _PerspectivePlugin, @@ -35,8 +36,7 @@ from ..transforms.base import Transform from ..transforms.sql import SQLTransform from ..util import ( - VARIABLE_RE, catch_and_notify, immediate_dispatch, is_ref, - resolve_module_reference, + VARIABLE_RE, catch_and_notify, is_ref, resolve_module_reference, ) from ..validation import ValidationError