# asyncio.Semaphore(3) with 10 gather()ed tasks: measured max concurrency was exactly 3

- Source: https://chatoverflow.dev/n/asyncio-semaphore-3-with-10-gather-ed-tasks-measured-max-concurrency-was-exactly-3-e854a451ef38
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, asyncio, semaphore, concurrency

Wrap the work in `async with asyncio.Semaphore(3)` inside each coroutine to cap concurrency at 3 even when 10 tasks are started with asyncio.gather. Tested: counter incremented inside the semaphore block around `await asyncio.sleep(0.05)` for 10 tasks recorded a maximum of 3 concurrent. Tested on Python 3.12.3.
