From d6d39fc8737c68e1b9232350d22bc58f1b87639a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Sat, 2 Aug 2025 20:39:59 -0700 Subject: [PATCH] TaskObserver: don't inspect on_push_frame signature for every frame --- CHANGELOG.md | 5 +++++ src/pipecat/pipeline/task_observer.py | 29 ++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84f7c7047..671e0c771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue with the `TavusVideoService` where an error was thrown due to missing transcription callbacks. +### Performance + +- Fixed an issue in `TaskObserver` (a proxy to all observers) that was degrading + global performance. + ## [0.0.77] - 2025-07-31 ### Added diff --git a/src/pipecat/pipeline/task_observer.py b/src/pipecat/pipeline/task_observer.py index cd46f85ef..532ef7977 100644 --- a/src/pipecat/pipeline/task_observer.py +++ b/src/pipecat/pipeline/task_observer.py @@ -153,22 +153,23 @@ class TaskObserver(BaseObserver): async def _proxy_task_handler(self, queue: asyncio.Queue, observer: BaseObserver): """Handle frame processing for a single observer.""" - warning_reported = False + on_push_frame_deprecated = False + signature = inspect.signature(observer.on_push_frame) + if len(signature.parameters) > 1: + import warnings + + with warnings.catch_warnings(): + warnings.simplefilter("always") + warnings.warn( + "Observer `on_push_frame(source, destination, frame, direction, timestamp)` is deprecated, us `on_push_frame(data: FramePushed)` instead.", + DeprecationWarning, + ) + + on_push_frame_deprecated = True + while True: data = await queue.get() - - signature = inspect.signature(observer.on_push_frame) - if len(signature.parameters) > 1: - if not warning_reported: - import warnings - - with warnings.catch_warnings(): - warnings.simplefilter("always") - warnings.warn( - "Observer `on_push_frame(source, destination, frame, direction, timestamp)` is deprecated, us `on_push_frame(data: FramePushed)` instead.", - DeprecationWarning, - ) - warning_reported = True + if on_push_frame_deprecated: await observer.on_push_frame( data.src, data.dst, data.frame, data.direction, data.timestamp )