Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion mesop/runtime/context.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import logging
import threading
import types
import urllib.parse as urlparse
Expand All @@ -23,6 +24,8 @@

Handler = Callable[[Any], Generator[None, None, None] | None]

logger = logging.getLogger(__name__)


@dataclass(kw_only=True)
class NodeSlot:
Expand Down Expand Up @@ -109,9 +112,12 @@ class Context:
def __init__(
self,
states: dict[type[Any], object],
*,
debug_mode: bool = False,
) -> None:
self._node_tree_state = NodeTreeState()
self._states: dict[type[Any], object] = states
self._debug_mode = debug_mode
# Previous states is used for performing state diffs.
self._previous_states: dict[type[Any], object] = copy.deepcopy(states)
self._handlers: dict[str, Handler] = {}
Expand Down Expand Up @@ -383,6 +389,9 @@ def run_event_handler(
else:
yield
else:
raise MesopException(
error_message = (
f"Unknown handler id: {event.handler_id} from event {event}"
)
if self._debug_mode:
raise MesopDeveloperException(error_message)
logger.warning(error_message)
4 changes: 3 additions & 1 deletion mesop/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def create_context(self) -> Context:
for state_class in self._state_classes:
states[state_class] = state_class()

return Context(states=cast(dict[Any, Any], states))
return Context(
states=cast(dict[Any, Any], states), debug_mode=self.debug_mode
)

def wait_for_hot_reload(self):
# If hot reload is in-progress, the path may not be registered yet because the client reload
Expand Down
Loading