task_manager
Asyncio task management.
This module provides task management functionality. Includes both abstract base classes and concrete implementations for managing asyncio tasks with comprehensive monitoring and cleanup capabilities.
- class pipecat.utils.asyncio.task_manager.TaskManagerParams(**kwargs)[source]
Bases:
objectConfiguration parameters for task manager initialization.
Deprecated since version 1.5.0: Use
TaskManager(passloopto its constructor) instead. Will be removed in 2.0.0.- Parameters:
loop – The asyncio event loop to use for task management.
- class pipecat.utils.asyncio.task_manager.BaseTaskManager[source]
Bases:
ABCAbstract base class for asyncio task management.
Provides the interface for creating, monitoring, and managing asyncio tasks.
- abstractmethod get_event_loop() AbstractEventLoop[source]
Get the event loop used by this task manager.
- Returns:
The asyncio event loop instance.
- abstractmethod create_task(coroutine: Coroutine, name: str, context: Context | None = None) Task[source]
Creates and schedules a new asyncio Task that runs the given coroutine.
The task is added to a global set of created tasks.
- Parameters:
coroutine – The coroutine to be executed within the task.
name – The name to assign to the task for identification.
context – Optional context manager to use when creating the task.
- Returns:
The created task object.
- abstractmethod async cancel_task(task: Task, timeout: float | None = None)[source]
Cancels the given asyncio Task and awaits its completion with an optional timeout.
This function removes the task from the set of registered tasks upon completion or failure.
Cancelling the task this call runs on is logged and ignored, since awaiting your own task never completes.
- Parameters:
task – The task to be cancelled.
timeout – The optional timeout in seconds to wait for the task to cancel.
- class pipecat.utils.asyncio.task_manager.TaskData(task: Task)[source]
Bases:
objectInternal data structure for tracking task metadata.
- Parameters:
task – The asyncio Task being managed.
- class pipecat.utils.asyncio.task_manager.TaskManager(*, context: Context | None = None, loop: AbstractEventLoop | None = None)[source]
Bases:
BaseTaskManagerConcrete implementation of BaseTaskManager.
Manages asyncio tasks. Provides comprehensive task lifecycle management including creation, monitoring, cancellation, and cleanup.
- __init__(*, context: Context | None = None, loop: AbstractEventLoop | None = None) None[source]
Initialize the task manager with empty task registry.
- Parameters:
context – Optional context manager to use when creating tasks.
loop – Event loop to use. If None, uses the current running loop.
- setup(params: TaskManagerParams)[source]
Initialize the task manager with configuration parameters.
Deprecated since version 1.5.0: Use the
TaskManagerconstructor (loop/context) instead. Will be removed in 2.0.0.- Parameters:
params – Configuration parameters for task management.
- get_event_loop() AbstractEventLoop[source]
Get the event loop used by this task manager.
- Returns:
The asyncio event loop instance.
- create_task(coroutine: Coroutine, name: str, context: Context | None = None) Task[source]
Creates and schedules a new asyncio Task that runs the given coroutine.
The task is added to a global set of created tasks.
- Parameters:
coroutine – The coroutine to be executed within the task.
name – The name to assign to the task for identification.
context – Optional context manager to use when creating the task.
- Returns:
The created task object.
- Raises:
Exception – If the task manager is not properly set up.
- async cancel_task(task: Task, timeout: float | None = None)[source]
Cancels the given asyncio Task and awaits its completion with an optional timeout.
This function removes the task from the set of registered tasks upon completion or failure.
Cancelling the task this call runs on is logged and ignored, since awaiting your own task never completes.
- Parameters:
task – The task to be cancelled.
timeout – The optional timeout in seconds to wait for the task to cancel.
- Raises:
asyncio.CancelledError – If the calling task is itself cancelled while waiting for
taskto finish cancelling.