processors(rtvi): fix task cleanup

This commit is contained in:
Aleix Conchillo Flaqué
2024-07-22 15:01:45 -07:00
parent 9233bb490c
commit 65cdf50774
5 changed files with 8 additions and 0 deletions

View File

@@ -59,5 +59,6 @@ class AsyncFrameProcessor(FrameProcessor):
(frame, direction) = await self._push_queue.get() (frame, direction) = await self._push_queue.get()
await self.push_frame(frame, direction) await self.push_frame(frame, direction)
running = not isinstance(frame, EndFrame) running = not isinstance(frame, EndFrame)
self._push_queue.task_done()
except asyncio.CancelledError: except asyncio.CancelledError:
break break

View File

@@ -316,6 +316,7 @@ class RTVIProcessor(FrameProcessor):
try: try:
(frame, direction) = await self._frame_queue.get() (frame, direction) = await self._frame_queue.get()
await self._handle_frame(frame, direction) await self._handle_frame(frame, direction)
self._frame_queue.task_done()
except asyncio.CancelledError: except asyncio.CancelledError:
break break

View File

@@ -114,9 +114,11 @@ class CartesiaTTSService(TTSService):
try: try:
if self._context_appending_task: if self._context_appending_task:
self._context_appending_task.cancel() self._context_appending_task.cancel()
await self._context_appending_task
self._context_appending_task = None self._context_appending_task = None
if self._receive_task: if self._receive_task:
self._receive_task.cancel() self._receive_task.cancel()
await self._receive_task
self._receive_task = None self._receive_task = None
if self._websocket: if self._websocket:
ws = self._websocket ws = self._websocket

View File

@@ -104,6 +104,7 @@ class BaseInputTransport(FrameProcessor):
try: try:
(frame, direction) = await self._push_queue.get() (frame, direction) = await self._push_queue.get()
await self.push_frame(frame, direction) await self.push_frame(frame, direction)
self._push_queue.task_done()
except asyncio.CancelledError: except asyncio.CancelledError:
break break
@@ -185,6 +186,8 @@ class BaseInputTransport(FrameProcessor):
# Push audio downstream if passthrough. # Push audio downstream if passthrough.
if audio_passthrough: if audio_passthrough:
await self._internal_push_frame(frame) await self._internal_push_frame(frame)
self._audio_in_queue.task_done()
except asyncio.CancelledError: except asyncio.CancelledError:
break break
except Exception as e: except Exception as e:

View File

@@ -204,6 +204,7 @@ class BaseOutputTransport(FrameProcessor):
try: try:
(frame, direction) = await self._push_queue.get() (frame, direction) = await self._push_queue.get()
await self.push_frame(frame, direction) await self.push_frame(frame, direction)
self._push_queue.task_done()
except asyncio.CancelledError: except asyncio.CancelledError:
break break