Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: move WesocketHandler's class vars to instance vars (#650)

Myles Scolnick0872384d8903
diff --git a/marimo/_server/api/endpoints/ws.py b/marimo/_server/api/endpoints/ws.py
index fdd47151e3..382b4d14b8 100644
--- a/marimo/_server/api/endpoints/ws.py
+++ b/marimo/_server/api/endpoints/ws.py
@@ -51,6 +51,12 @@ async def websocket_endpoint(
class WebsocketHandler(SessionHandler):
+ """WebSocket that sessions use to send messages to frontends.
+
+ Each new socket gets a unique session. At most one session can exist when
+ in edit mode.
+ """
+
def __init__(
self,
websocket: WebSocket,
@@ -62,19 +68,12 @@ class WebsocketHandler(SessionHandler):
self.manager = manager
self.session_id = session_id
self.mode = mode
-
- """WebSocket that sessions use to send messages to frontends.
-
- Each new socket gets a unique session. At most one session can exist when
- in edit mode.
- """
-
- status: ConnectionState
- cancel_close_handle: Optional[asyncio.TimerHandle] = None
- heartbeat_task: Optional[asyncio.Task[None]] = None
- # Messages from the kernel are put in this queue
- # to be sent to the frontend
- message_queue: asyncio.Queue[Tuple[str, Any]]
+ self.status: ConnectionState
+ self.cancel_close_handle: Optional[asyncio.TimerHandle] = None
+ self.heartbeat_task: Optional[asyncio.Task[None]] = None
+ # Messages from the kernel are put in this queue
+ # to be sent to the frontend
+ self.message_queue: asyncio.Queue[Tuple[str, Any]]
async def _write_kernel_ready(self) -> None:
"""Communicates to the client that the kernel is ready.