{"id":7908,"library":"aiodebug","title":"AioDebug","description":"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.","status":"active","version":"2.3.0","language":"en","source_language":"en","source_url":"https://gitlab.com/quantlane/libs/aiodebug","tags":["asyncio","debugging","monitoring","performance"],"install":[{"cmd":"pip install aiodebug","lang":"bash","label":"pip"},{"cmd":"poetry add aiodebug","lang":"bash","label":"Poetry"}],"dependencies":[{"reason":"Used for logging if installed, otherwise defaults to the standard logging module.","package":"logwood","optional":true}],"imports":[{"symbol":"log_slow_callbacks","correct":"import aiodebug.log_slow_callbacks"},{"symbol":"monitor_loop_lag","correct":"import aiodebug.monitor_loop_lag"},{"symbol":"hang_inspection","correct":"import aiodebug.hang_inspection"}],"quickstart":{"code":"import asyncio\nimport time\nimport logging\nimport aiodebug.log_slow_callbacks\n\nlogging.basicConfig(level=logging.WARNING)\n\nasync def slow_task():\n    print(\"Starting slow task...\")\n    # Simulate a blocking I/O operation or CPU-bound task\n    time.sleep(0.1) \n    print(\"Slow task finished.\")\n\nasync def main():\n    print(\"Enabling slow callback logging...\")\n    aiodebug.log_slow_callbacks.enable(0.05) # Log callbacks slower than 0.05 seconds\n    print(\"Running main task...\")\n    await asyncio.sleep(0.01) # Small non-blocking sleep\n    await slow_task()\n    print(\"Main task finished.\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"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."},"warnings":[{"fix":"Always check the project's PyPI page or GitHub README for the most current repository link.","message":"The official GitHub repository at `qntln/aiodebug` states that the project has moved to `gitlab.com/quantlane/libs/aiodebug`. Users looking for the most up-to-date source code, issues, or contributions should refer to the GitLab instance.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Understand that `aiodebug` targets event loop blocking. For overall long-running *asynchronous* tasks, traditional profiling tools or custom instrumentation might be more appropriate.","message":"`aiodebug` primarily identifies *blocking* calls that prevent the `asyncio` event loop from progressing. It does not report on `asyncio`-friendly tasks that simply have a long overall execution time but yield correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Structure your `asyncio` code to encapsulate potentially blocking operations within their own distinct `async` functions or `Task`s where possible, and avoid direct blocking calls within critical path coroutines, or use `asyncio.to_thread` for CPU-bound work.","message":"When using `aiodebug.log_slow_callbacks`, if a parent coroutine directly `await`s a blocking function, `aiodebug` might report the parent coroutine as slow, rather than pinpointing the exact blocking sub-task. This can be misleading.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Review the indicated coroutine (`some_function`) and identify the blocking operation. Consider using `asyncio.to_thread()` for CPU-bound tasks, ensuring I/O operations are truly asynchronous, or breaking down long synchronous operations.","cause":"A coroutine or callback blocked the `asyncio` event loop for longer than the threshold set in `aiodebug.log_slow_callbacks.enable()`.","error":"WARNING: Executing <Task pending coro=<some_function() running at ...> ...> took X.YYY seconds"},{"fix":"Import the specific submodule that contains the desired feature, for example, `import aiodebug.log_slow_callbacks` to use `aiodebug.log_slow_callbacks.enable()`.","cause":"Attempting to access a `aiodebug` feature directly from the `aiodebug` top-level module (e.g., `aiodebug.enable_slow_callbacks`). The library's functionalities are organized into submodules.","error":"AttributeError: module 'aiodebug' has no attribute 'some_feature_name'"}]}