Skip to main content

asyncio Eventloop Blockers Detector/Analyzer.

Project description

LoopSentry

Asyncio Event Loop Blockers Detector & Analyzer

  • utility for detecting blocking calls in asyncio event loops

LoopSentry Interface

Installation

uv add loopsentry

pip way

pip install loopsentry

Usage

  1. Basic Usage
import asyncio
from loopsentry import LoopSentry

async def main():
    # start monitoring (default threshold: 0.1s) ie: if blocks is >= 0.1 , it is logged
    sentry = LoopSentry(threshold=0.1,
                        capture_args=False, # this is basically do you want to capture arguments of functions at the time
                        detect_async_bottlenecks=False) # other than blocking it also detects slow asyncio tasks which are going on. helps to find bottlenecks
    sentry.start()

    print("Running...")
    ... # rest of your application

if __name__ == "__main__":
    asyncio.run(main())
  1. Use inside Uvicorn/gunicorn workers in fastapi
  • you need to put it inside a lifespan context manager , so if you use multiple workers eachh gets their own LoopSentry instance
from contextlib import asynccontextmanager
from fastapi import FastAPI
from loopsentry import LoopSentry

@asynccontextmanager
async def lifespan(app: FastAPI):
    sentry = LoopSentry()
    sentry.start()
    yield

app = FastAPI(lifespan=lifespan)

@app.get("/")
async def root():
    return {"message": "I am being monitored!"}

Log Analysis

uv run loopsentry analyze -d log_directory

NOTE: if you used pip to install then

loopsentry analyze -d log_directory

CLI Controls

  • /text: Search/Filter logs.
  • g: Group view (see top offenders).
  • s: Sort by Duration vs Time.
  • ID: Enter an ID number to view stack trace & arguments.

Gallery

1. Traceback with Argument Capture

Pinpoint exactly where the code blocked and what arguments caused it. Traceback View

2. Grouped View (Top Offenders)

Quickly identify which files or functions are causing the most performance hits. Grouped View

3. Slow Async Task Detection

Detect tasks that are async but still taking too long (Bottlenecks). Slow Async View

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loopsentry-0.1.1.tar.gz (244.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loopsentry-0.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file loopsentry-0.1.1.tar.gz.

File metadata

  • Download URL: loopsentry-0.1.1.tar.gz
  • Upload date:
  • Size: 244.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for loopsentry-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f71cd7b6f363dfb7b7456a539a3ef1173f17c7e378510efeb553b9d471547a15
MD5 4d27be0f0f04f9e447143f902d495e29
BLAKE2b-256 95f5055eea3fa6eb9b9532781bb059a4d7ab89bda932626ed3e9928875df9e8e

See more details on using hashes here.

File details

Details for the file loopsentry-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: loopsentry-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for loopsentry-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 55e1e035d7e0249146f0dc1b9c39994855524b989522e987c29afd08910d1b02
MD5 4ed9f98342debcf18fb0febe2f78585b
BLAKE2b-256 d5e3ad12b595ba06f2f8887008aeda50997dd6995b559a9fbb9bb6e84c9f17cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page