Skip to content

Commit 0c19a6d

Browse files
authored
Refactor agent.py for improved command handling
1 parent fba1546 commit 0c19a6d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

backend/agent.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ async def run_agent():
110110
await websocket.send(json.dumps(auth_payload))
111111

112112
# 2. Handle commands asynchronously
113+
command_task = asyncio.create_task(handle_commands(websocket))
114+
113115
try:
114116
counter = 0
115117
while True:
@@ -122,6 +124,10 @@ async def run_agent():
122124
await asyncio.sleep(UPDATE_INTERVAL)
123125
finally:
124126
command_task.cancel()
127+
try:
128+
await command_task
129+
except asyncio.CancelledError:
130+
pass
125131

126132
except Exception as e:
127133
print(f"❌ Connection error: {e}. Retrying in 5s...")

0 commit comments

Comments
 (0)