Catch event-loop blocking in FastAPI and see which requests were in flight.
When something blocks your event loop (via time.sleep(), blocking I/O, or CPU work), LoopGuard detects it and narrows it down to the requests that were in flight when the loop stalled. The sentinel measures loop lag, so it cannot name the single guilty handler — it reports every request that was active during the stall.
Install
pip install fastapi-loopguard
Quick Start
from fastapi import FastAPI
from fastapi_loopguard import LoopGuardMiddleware
app = FastAPI()
app.add_middleware(LoopGuardMiddleware)
Enforcement Modes
| Mode | Behavior | Use Case |
|---|---|---|
"warn" |
Console warnings + headers | Default |
"strict" |
HTTP 503 + error page | Development / CI |
"log" |
Silent logging | Production |
from fastapi_loopguard import LoopGuardConfig
# Development: diagnostic headers on every response
config = LoopGuardConfig(dev_mode=True)
# Development / CI: fail loudly with an educational 503
config = LoopGuardConfig(enforcement_mode="strict")
# Production: silent logging
config = LoopGuardConfig(enforcement_mode="log")
app.add_middleware(LoopGuardMiddleware, config=config)
What You Get
Strict Mode
Returns an educational 503 page that explains what went wrong and how to fix it:
Warn Mode
Adds diagnostic headers to every response for debugging:
Log Mode
Writes structured logs listing the requests that were in flight:
Release files for fastapi-loopguard 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_loopguard-0.5.0.tar.gz | 380.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_loopguard-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 404.2 kB
Release files / fastapi_loopguard-0.5.0.tar.gz
| Download URL | fastapi_loopguard-0.5.0.tar.gz |
|---|---|
| Size | 380.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e96b8813f10cdec702655c7b7ed5121beb2e6396031776b0646636fe7ff4ceb6
|
|
BLAKE2b-256 checksum How to use checksums |
a48c2558edac550ae01361b2990b027492fcdd84e3d449b971eb6be3757da816
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.
Transparency logRelease files / fastapi_loopguard-0.5.0-py3-none-any.whl
| Download URL | fastapi_loopguard-0.5.0-py3-none-any.whl |
|---|---|
| Size | 23.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
429a371ef5eb006464a74d317b838a8e2998e11c87dd16158e8bef04d506ddaf
|
|
BLAKE2b-256 checksum How to use checksums |
952a9f483c30f3b03bd7e337cba297e18d216dd5e82e8a50feb9dd3a6e1b59f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.
Transparency log