What is async programming?
Running multiple I/O tasks concurrently without blocking the entire program.
Difference between blocking and non-blocking?
Blocking → whole program waits
Non-blocking → only current task pauses, others run
What is a coroutine?
An async function that returns a coroutine object (task plan) and runs only when awaited or scheduled.
What happens when you call an async function?
It does NOT execute — it creates a coroutine object.
Difference between async and await?
async → defines coroutine
await → executes and pauses it
What is the event loop?
The scheduler that runs and switches between async tasks.
What does asyncio.run() do?
Starts the event loop and runs the async program (used once at top-level).
What does asyncio.gather() do?
Runs multiple coroutines concurrently and waits for all results.
Why do we use await inside function AND await gather()?
Inside → wait for one task
gather → wait for all tasks
Why doesn’t fetch() execute immediately?
Because async functions are lazy — they only run when awaited or scheduled.
What is a session in aiohttp?
A reusable connection that avoids reconnecting for every request.
Difference between aiohttp and requests?
requests → blocking
aiohttp → non-blocking, supports concurrency
Why use aiohttp.ClientSession()?
To reuse connections and improve performance for multiple requests.
How do we fetch multiple URLs efficiently?
Create coroutines → run using asyncio.gather().
How does async weather API work?
Client → FastAPI → async function → external API → response
When should async be used?
API calls, DB queries, network I/O (not CPU-heavy tasks).
What is the core idea of async?
Don’t wait idle — do other work while waiting.
🚀 Ultra-Short Revision
async → define
await → execute
coroutine → task plan
gather → run many
event loop → manager
session → reuse connection
aiohttp → async requests