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

attempt to fix hotreload for ws #1096

Closed
wants to merge 1 commit into from
Closed
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
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)
Loading