Skip to content

Commit

Permalink
defer imports to get around perspective cloudpickle incompatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Paine <[email protected]>
  • Loading branch information
timkpaine committed Nov 16, 2024
1 parent 1225ddc commit 8cd7d3a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions raydar/dashboard/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@
from ray.serve import Application, deployment, ingress

if parse(perspective_version) >= parse("3"):
from perspective import Server as PerspectiveServer, Table
from perspective.handlers.starlette import PerspectiveStarletteHandler

PERSPECTIVE_3 = True
else:
from perspective import PerspectiveManager as PerspectiveServer, Table
from perspective.handlers import PerspectiveStarletteHandler

PERSPECTIVE_3 = False

class PerspectiveRayServerArgs(BaseModel):
Expand Down Expand Up @@ -53,6 +47,11 @@ def __init__(self, args: PerspectiveRayServerArgs = None):
self._psp_server = None

def _init(self):
if PERSPECTIVE_3:
from perspective import Server as PerspectiveServer
else:
from perspective import PerspectiveManager as PerspectiveServer

if self._psp_server is None:
self._psp_server = PerspectiveServer()
if PERSPECTIVE_3:
Expand All @@ -68,8 +67,10 @@ def new_table(self, tablename: str, schema) -> None:
return self._schemas[tablename]
self._schemas[tablename] = schema
if PERSPECTIVE_3:
self._psp_client.table(schema, name=tablename)
self._tables[tablename] = self._psp_client.table(schema, name=tablename)
else:
from perspective import Table

self._tables[tablename] = Table(schema)
self._psp_client.host_table(tablename, self._tables[tablename])

Expand All @@ -87,8 +88,10 @@ def update(self, tablename: str, data):
@app.websocket("/ws")
async def ws(self, ws: WebSocket):
if PERSPECTIVE_3:
from perspective.handlers.starlette import PerspectiveStarletteHandler
handler = PerspectiveStarletteHandler(perspective_server=self._psp_server, websocket=ws)
else:
from perspective.handlers import PerspectiveStarletteHandler
handler = PerspectiveStarletteHandler(manager=self._psp_server, websocket=ws)
try:
await handler.run()
Expand Down

0 comments on commit 8cd7d3a

Please sign in to comment.