frame_queue
Frame queue utilities for Pipecat pipeline processors.
- class pipecat.utils.frame_queue.FrameQueue(frame_getter: ~collections.abc.Callable[[~typing.Any], ~pipecat.frames.frames.Frame] = <function FrameQueue.<lambda>>)[source]
Bases:
QueueAn asyncio.Queue that tracks whether any UninterruptibleFrame is enqueued.
Extends
asyncio.Queueand maintains an O(1)has_uninterruptibleflag so interrupt-handling code can decide whether to cancel a task or merely drain non-uninterruptible items without scanning the queue.Items may be raw
Frameobjects or tuples whose first element is aFrame(e.g.(frame, direction, callback)). Pass aframe_gettercallable to extract the frame from each item; the default treats the item itself as the frame.Also exposes a
reset()helper that drains all non-UninterruptibleFrameitems while keeping uninterruptible ones in place.- __init__(frame_getter: ~collections.abc.Callable[[~typing.Any], ~pipecat.frames.frames.Frame] = <function FrameQueue.<lambda>>)[source]
Initialize the FrameQueue.
- Parameters:
frame_getter – Callable that extracts a
Framefrom a queue item. Defaults to the identity function (item is a rawFrame). Passlambda item: item[0]when items are(frame, direction, callback)tuples.
- has_frame(frame_type: type[Frame] | type[UninterruptibleFrame]) bool[source]
Return True if any frame of the given type is in the queue.
frame_typemay beFrame,UninterruptibleFrame(a mixin, not aFramesubclass), or any concrete frame type.Note
This inspects the internal _queue (deque) of asyncio.Queue. This is not part of the public API but is stable in CPython.
- Parameters:
frame_type – The frame class to check for.
- Returns:
True if at least one enqueued frame is an instance of
frame_type.
- property has_uninterruptible: bool
Return True if any UninterruptibleFrame is currently in the queue.