From 63f5db967405b23b828eb894653ca341c2b0237d Mon Sep 17 00:00:00 2001 From: Dillon DuPont Date: Thu, 10 Jul 2025 15:24:46 -0400 Subject: [PATCH] Added thread pool --- libs/python/computer-server/computer_server/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/python/computer-server/computer_server/main.py b/libs/python/computer-server/computer_server/main.py index f8401eb8..1131e335 100644 --- a/libs/python/computer-server/computer_server/main.py +++ b/libs/python/computer-server/computer_server/main.py @@ -237,7 +237,9 @@ async def websocket_endpoint(websocket: WebSocket): if asyncio.iscoroutinefunction(handler_func): result = await handler_func(**filtered_params) else: - result = handler_func(**filtered_params) + # Run sync functions in thread pool to avoid blocking event loop + loop = asyncio.get_event_loop() + result = await loop.run_in_executor(None, lambda: handler_func(**filtered_params)) await websocket.send_json({"success": True, **result}) except Exception as cmd_error: logger.error(f"Error executing command {command}: {str(cmd_error)}") @@ -364,7 +366,9 @@ async def cmd_endpoint( if asyncio.iscoroutinefunction(handler_func): result = await handler_func(**filtered_params) else: - result = handler_func(**filtered_params) + # Run sync functions in thread pool to avoid blocking event loop + loop = asyncio.get_event_loop() + result = await loop.run_in_executor(None, lambda: handler_func(**filtered_params)) # Stream the successful result response_data = {"success": True, **result}