From 45e1136a90dc37f9bcf12b1882db629b81684b9c Mon Sep 17 00:00:00 2001 From: Dillon DuPont Date: Thu, 10 Jul 2025 15:28:46 -0400 Subject: [PATCH] Use to_thread instead --- libs/python/computer-server/computer_server/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/python/computer-server/computer_server/main.py b/libs/python/computer-server/computer_server/main.py index 1131e335..f28fed73 100644 --- a/libs/python/computer-server/computer_server/main.py +++ b/libs/python/computer-server/computer_server/main.py @@ -238,8 +238,7 @@ async def websocket_endpoint(websocket: WebSocket): result = await handler_func(**filtered_params) else: # 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)) + result = await asyncio.to_thread(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)}") @@ -367,8 +366,7 @@ async def cmd_endpoint( result = await handler_func(**filtered_params) else: # 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)) + result = await asyncio.to_thread(handler_func, **filtered_params) # Stream the successful result response_data = {"success": True, **result}