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 | None] = <function FrameQueue.<lambda>>)[source]

Bases: Queue

An asyncio.Queue that knows whether any uninterruptible frame is enqueued.

Extends asyncio.Queue with has_uninterruptible, so interrupt-handling code can decide whether to cancel a task or merely drain the interruptible items, and with reset(), which does that draining: it removes every interruptible item and keeps the uninterruptible ones (Frame.interruptible False) in place. Both read the frames’ flags as they are at that moment.

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. Queues that also carry non-frame items should return None from their getter for those.

__init__(frame_getter: ~collections.abc.Callable[[~typing.Any], ~pipecat.frames.frames.Frame | None] = <function FrameQueue.<lambda>>)[source]

Initialize the FrameQueue.

Parameters:

frame_getter – Callable that extracts a Frame from a queue item, or None when the item holds no frame. 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]) → bool[source]

Return True if any frame of the given type is in the queue.

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 uninterruptible frame is currently in the queue.

reset() → None[source]

Remove all interruptible items, keeping uninterruptible ones.