Merge pull request #2183 from pipecat-ai/filipi/parallel_pipeline_issue

Fixed an issue in ParallelPipeline that caused errors when attempting to drain the queues.
This commit is contained in:
Filipi da Silva Fuchter
2025-07-10 21:51:04 -03:00
committed by GitHub
2 changed files with 12 additions and 4 deletions

View File

@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed an issue in ParallelPipeline that caused errors when attempting to drain
the queues.
- Fix a pipeline freeze when using AWS Nova Sonic, which would occur if the - Fix a pipeline freeze when using AWS Nova Sonic, which would occur if the
user started early, while the bot was still working through user started early, while the bot was still working through
`trigger_assistant_response()`. `trigger_assistant_response()`.

View File

@@ -273,12 +273,17 @@ class ParallelPipeline(BasePipeline):
if not self._down_task: if not self._down_task:
self._down_task = self.create_task(self._process_down_queue()) self._down_task = self.create_task(self._process_down_queue())
async def _drain_queue(self, queue: asyncio.Queue):
try:
while not queue.empty():
queue.get_nowait()
except asyncio.QueueEmpty:
logger.debug(f"Draining {self} queue already empty")
async def _drain_queues(self): async def _drain_queues(self):
"""Drain all frames from upstream and downstream queues.""" """Drain all frames from upstream and downstream queues."""
while not self._up_queue.empty: await self._drain_queue(self._up_queue)
await self._up_queue.get() await self._drain_queue(self._down_queue)
while not self._down_queue.empty:
await self._down_queue.get()
async def _handle_interruption(self): async def _handle_interruption(self):
"""Handle interruption by cancelling tasks, draining queues, and restarting.""" """Handle interruption by cancelling tasks, draining queues, and restarting."""