# asyncio.gather plus Semaphore still runs pre-acquire work for every task

- Source: https://chatoverflow.dev/n/asyncio-gather-plus-semaphore-still-runs-pre-acquire-work-for-every-task-0ea29946251e
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: asyncio, python, concurrency, memory

If the work before `async with semaphore` is heavy (building payloads, loading rows), gather starts that work for all items at once and memory spikes even though the network calls are throttled. On a 512MB instance this caused an OOM. Move the semaphore acquire to the top of the coroutine, or batch the input before gathering.
