From bbe01d10ef3c93a0172fcdd55ffa579ed6a0131a Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Wed, 6 Aug 2025 12:42:58 -0300 Subject: [PATCH] Fixed an issue in BaseOutputTransport where the loop could consume all CPU. --- CHANGELOG.md | 6 ++++++ src/pipecat/transports/base_output.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a552daed8..46a4082eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed an issue in the `BaseOutputTransport`, mainly reproducible with + `FastAPIWebsocketOutputTransport` when the audio mixer was enabled, where the + loop could consume 100% CPU by continuously returning without delay, preventing + other asyncio tasks (such as cancellation or shutdown signals) from being + processed. + - Fixed an issue where `BotStartedSpeakingFrame` and `BotStoppedSpeakingFrame` were not emitted when using `TavusVideoService` or `HeyGenVideoService`. diff --git a/src/pipecat/transports/base_output.py b/src/pipecat/transports/base_output.py index 313c36fc0..9c2da1d22 100644 --- a/src/pipecat/transports/base_output.py +++ b/src/pipecat/transports/base_output.py @@ -658,6 +658,11 @@ class BaseOutputTransport(FrameProcessor): num_channels=self._params.audio_out_channels, ) yield frame + # Allow other asyncio tasks to execute by adding a small sleep + # Without this sleep, in task cancellation scenarios, this loop would + # continuously return without any delay, leading to 100% CPU utilization + # and preventing cancel/stop signals from being processed properly + await asyncio.sleep(0) if self._mixer: return with_mixer(BOT_VAD_STOP_SECS)