Event loop lock detector for Python.
pip install gadasyncblock
import contextlib
from fastapi import FastAPI
from gadasyncblock import AsyncBlock
# logger: asyncio.detector
detector = AsyncBlock(timeout=1)
@contextlib.asynccontextmanager
async def lifespan(_: FastAPI):
detector.start()
yield
detector.shutdown()
app = FastAPI(lifespan=lifespan)
@app.post("/run")
async def run():
time.sleep(2)
return {"message": "Blocked"}