Async Flashcards

(18 cards)

1
Q

What is async programming?

A

Running multiple I/O tasks concurrently without blocking the entire program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Difference between blocking and non-blocking?

A

Blocking → whole program waits
Non-blocking → only current task pauses, others run

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a coroutine?

A

An async function that returns a coroutine object (task plan) and runs only when awaited or scheduled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when you call an async function?

A

It does NOT execute — it creates a coroutine object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Difference between async and await?

A

async → defines coroutine
await → executes and pauses it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the event loop?

A

The scheduler that runs and switches between async tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does asyncio.run() do?

A

Starts the event loop and runs the async program (used once at top-level).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does asyncio.gather() do?

A

Runs multiple coroutines concurrently and waits for all results.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why do we use await inside function AND await gather()?

A

Inside → wait for one task
gather → wait for all tasks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why doesn’t fetch() execute immediately?

A

Because async functions are lazy — they only run when awaited or scheduled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a session in aiohttp?

A

A reusable connection that avoids reconnecting for every request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Difference between aiohttp and requests?

A

requests → blocking
aiohttp → non-blocking, supports concurrency

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why use aiohttp.ClientSession()?

A

To reuse connections and improve performance for multiple requests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do we fetch multiple URLs efficiently?

A

Create coroutines → run using asyncio.gather().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does async weather API work?

A

Client → FastAPI → async function → external API → response

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When should async be used?

A

API calls, DB queries, network I/O (not CPU-heavy tasks).

17
Q

What is the core idea of async?

A

Don’t wait idle — do other work while waiting.

18
Q

🚀 Ultra-Short Revision
async → define
await → execute
coroutine → task plan
gather → run many
event loop → manager
session → reuse connection
aiohttp → async requests