From 5e5060a6fe998a71d694bec6fc54d8c18488ec2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Mon, 19 May 2025 09:24:56 -0700 Subject: [PATCH] BaseObject: don't create event handler tasks if none is registered --- CHANGELOG.md | 9 ++++++++- src/pipecat/utils/base_object.py | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 086b05861..051e344fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,7 +81,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fixed an issue with `CartesiaTTSService` where `TTSTextFrame` messages weren't being emitted when the model was set to `sonic`. This resulted in the assistant context not being updated with assistant messages. +- Fixed an issue with `CartesiaTTSService` where `TTSTextFrame` messages weren't + being emitted when the model was set to `sonic`. This resulted in the + assistant context not being updated with assistant messages. + +### Performance + +- Don't create event handler tasks if no user event handlers have been + registered. ### Other diff --git a/src/pipecat/utils/base_object.py b/src/pipecat/utils/base_object.py index deb10d1b1..49705a899 100644 --- a/src/pipecat/utils/base_object.py +++ b/src/pipecat/utils/base_object.py @@ -59,6 +59,11 @@ class BaseObject(ABC): self._event_handlers[event_name] = [] async def _call_event_handler(self, event_name: str, *args, **kwargs): + # If we haven't registered an event handler, we don't need to do + # anything. + if not self._event_handlers.get(event_name): + return + # Create the task. task = asyncio.create_task(self._run_task(event_name, *args, **kwargs))