AioDebug

2.3.0 · active · verified Thu Apr 16

AioDebug is a lightweight Python library designed for monitoring and testing `asyncio` programs. It provides features like logging slow callbacks, tracking event loop lags, and dumping stack traces for unresponsive loops, intended for always-on use in production environments. The current version is 2.3.0, released on January 4, 2022. It has an infrequent release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `aiodebug.log_slow_callbacks` to identify and log `asyncio` callbacks that block the event loop for longer than a specified duration. The `slow_task` simulates a blocking operation (using `time.sleep`) which `aiodebug` will detect and report.

import asyncio
import time
import logging
import aiodebug.log_slow_callbacks

logging.basicConfig(level=logging.WARNING)

async def slow_task():
    print("Starting slow task...")
    # Simulate a blocking I/O operation or CPU-bound task
    time.sleep(0.1) 
    print("Slow task finished.")

async def main():
    print("Enabling slow callback logging...")
    aiodebug.log_slow_callbacks.enable(0.05) # Log callbacks slower than 0.05 seconds
    print("Running main task...")
    await asyncio.sleep(0.01) # Small non-blocking sleep
    await slow_task()
    print("Main task finished.")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →