From 3a4517e8e930cc48fbaf69051ffd81a2808bbaa9 Mon Sep 17 00:00:00 2001 From: aoife cassidy Date: Thu, 22 Aug 2024 16:46:37 -0700 Subject: [PATCH] run job termination task asynchronously --- livekit-agents/livekit/agents/worker.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/livekit-agents/livekit/agents/worker.py b/livekit-agents/livekit/agents/worker.py index bfe9f62e3d..20464a1395 100644 --- a/livekit-agents/livekit/agents/worker.py +++ b/livekit-agents/livekit/agents/worker.py @@ -486,7 +486,9 @@ async def _recv_task(): elif which == "assignment": self._handle_assignment(msg.assignment) elif which == "termination": - await self._handle_termination(msg.termination) + user_task = self._loop.create_task(self._handle_termination(msg.termination), name="termination") + self._tasks.add(user_task) + user_task.add_done_callback(self._tasks.discard) tasks = [ asyncio.create_task(_load_task()),