Utils Module

Asyncio Utilities

chanx.utils.asyncio.create_task(coro: Coroutine[Any, Any, T], background_tasks: set[Task[Any]] | None = None, name: str | None = None, context: Context | None = None) Task[T]

Creates an asyncio task with proper cleanup and tracking.

This function creates a task from a coroutine, wrapping it with error handling and adding it to a set of background tasks for tracking. The task automatically removes itself from the tracking set when completed.

Parameters:
  • coro -- The coroutine to convert into a task

  • background_tasks -- Set to track the task (uses global set if None)

  • name -- Optional name for the task

  • context -- Optional context for the task. Only used in Python 3.11 and above. In Python 3.10, this parameter is accepted but ignored.

Returns:

The created asyncio task

Logging Utilities

chanx.utils.logging.logger = structlog.get_logger("chanx")

Pre-configured structured logger for the Chanx framework.