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: Queue

An asyncio.Queue that tracks whether any UninterruptibleFrame is enqueued.

Extends asyncio.Queue and maintains an O(1) has_uninterruptible flag 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 Frame objects or tuples whose first element is a Frame (e.g. (frame, direction, callback)). Pass a frame_getter callable 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-UninterruptibleFrame items 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 Frame from a queue item. Defaults to the identity function (item is a raw Frame). Pass lambda 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_type may be Frame, UninterruptibleFrame (a mixin, not a Frame subclass), 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.

reset() None[source]

Remove all non-UninterruptibleFrame items, keeping uninterruptible ones.