diff --git a/solara/server/starlette.py b/solara/server/starlette.py index a36dc2e6a..e9cd2d985 100644 --- a/solara/server/starlette.py +++ b/solara/server/starlette.py @@ -75,7 +75,8 @@ def __init__(self, ws: starlette.websockets.WebSocket, portal: anyio.from_thread self.ws = ws self.portal = portal self.to_send: List[Union[str, bytes]] = [] - self.task = asyncio.ensure_future(self.process_messages_task()) + if settings.main.experimental_performance: + self.task = asyncio.ensure_future(self.process_messages_task()) async def process_messages_task(self): while True: @@ -220,6 +221,8 @@ async def run(): thread_return = anyio.to_thread.run_sync(websocket_thread_runner, ws, portal) await thread_return finally: + if settings.main.experimental_performance: + ws_wrapper.task.cancel() try: await ws.close() except: # noqa