</>CodeWithKarani
All of Python & FastAPI
Python & FastAPI

Async & Concurrency

The event loop, blocking calls, Celery and background work.

6 articles

Python & FastAPI8 min read

Celery's unresolved worker memory leak: what actually helps when nothing fixes it

Celery's parent process RAM climbs for days with no confirmed cause upstream. Here is what the open issue really says, and the mitigations that hold your server up meanwhile.

Read
Python & FastAPI8 min read

The asyncio SSL Memory Leak Nobody Warns You About, and How to Work Around It

Long-running asyncio TLS services can leak memory in the SSL transport, growing RSS until the OOM killer strikes. Here is how to confirm it, mitigate it, and track the real fix.

Read
Python & FastAPI9 min read

pytest-asyncio 'event loop is already running': there is no patch coming

request.getfixturevalue() on an async fixture crashes pytest-asyncio, nest_asyncio no longer saves you, and upstream has no fix. Here is the test architecture that works instead.

Read
Python & FastAPI6 min read

Pydantic v2 'MockValSer object cannot be converted to SchemaSerializer': The Real Cause

This cryptic Pydantic v2 TypeError means your model schema never finished building, usually an unresolved forward reference. Here is the fix, not a workaround.

Read
Python & FastAPI7 min read

Why Your FastAPI 'async' Endpoints Run in Serial: The Blocking Event Loop Trap

FastAPI processing requests one at a time? async def does not make blocking code async. Here is why the event loop serialises, and the def vs async fix.

Read
Python & FastAPI7 min read

Celery Task Received but Not Executing: The Four Real Causes

Celery logs 'Received task' then runs nothing, with no error. It is one symptom with four unrelated causes. How to tell them apart with py-spy instead of guessing at flags.

Read