Skip to content

Commit

Permalink
attempt to fix hotreload for ws
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Nov 8, 2024
1 parent 8efc807 commit 848d06b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions mesop/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ def __init__(self):
self._state_classes: list[type[Any]] = []
self._loading_errors: list[pb.ServerError] = []
self._has_served_traffic = False
self._contexts = {}
self.websocket_contexts = {}

def context(self) -> Context:
if MESOP_WEBSOCKETS_ENABLED and hasattr(request, "websocket_session_id"):
websocket_session_id = request.websocket_session_id # type: ignore
if websocket_session_id not in self._contexts:
self._contexts[websocket_session_id] = self.create_context()
return self._contexts[websocket_session_id]
if websocket_session_id not in self.websocket_contexts:
self.websocket_contexts[websocket_session_id] = self.create_context()
return self.websocket_contexts[websocket_session_id]
if "_mesop_context" not in g:
g._mesop_context = self.create_context()
return g._mesop_context

def delete_context(self, websocket_session_id: str) -> None:
if websocket_session_id in self._contexts:
del self._contexts[websocket_session_id]
if websocket_session_id in self.websocket_contexts:
del self.websocket_contexts[websocket_session_id]
else:
warn(
f"Tried to delete context with websocket_session_id={websocket_session_id} that doesn't exist."
Expand Down Expand Up @@ -202,6 +202,7 @@ def reset_runtime(without_hot_reload: bool = False):
_runtime.debug_mode = old_runtime.debug_mode
_runtime.component_fns = old_runtime.component_fns
_runtime.event_mappers = old_runtime.event_mappers
_runtime.websocket_contexts = old_runtime.websocket_contexts


def enable_debug_mode():
Expand Down
2 changes: 1 addition & 1 deletion mesop/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Contains the version string."""

VERSION = "0.12.8"
VERSION = "0.12.9beta2"

if __name__ == "__main__":
print(VERSION)

0 comments on commit 848d06b

Please sign in to comment.