loopmon

raw JSON →
1.0.1 verified Mon Apr 27 auth: no python

Lightweight monitor library for asyncio event loop. Current version 1.0.1, maintenance mode with infrequent updates.

pip install loopmon
error AttributeError: module 'loopmon' has no attribute 'EventLoopMonitor'
cause Incorrect import (e.g., `from loopmon.monitor import EventLoopMonitor`).
fix
Use from loopmon import EventLoopMonitor.
error RuntimeError: Monitor is not running
cause Calling get_stats() before entering the context manager.
fix
Ensure get_stats() is called inside the async with monitor: block.
gotcha Monitor must be used as async context manager; otherwise, it won't start monitoring.
fix Use `async with monitor:` block.
gotcha get_stats() returns None if called outside the context manager block.
fix Call get_stats() inside the `async with` block.

Basic usage of EventLoopMonitor to monitor an asyncio event loop.

import asyncio
from loopmon import EventLoopMonitor

async def main():
    monitor = EventLoopMonitor()
    async with monitor:
        await asyncio.sleep(1)
    print(monitor.get_stats())

asyncio.run(main())