#8 – Concurrency and Parallelism Flashcards

(13 cards)

1
Q

What is concurrency in Python?

A

Concurrency means running multiple tasks at the same time conceptually, often by switching between them.

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

What is parallelism in Python?

A

Parallelism means actually running tasks simultaneously, typically using multiple CPU cores.

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

What is the difference between concurrency and parallelism?

A

Concurrency is about structure (tasks that can be paused/resumed), while parallelism is about simultaneous execution.

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

What is multithreading in Python?

A

Running multiple threads within the same process. Good for I/O-bound tasks.

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

What limits Python threads from true parallelism?

A

The Global Interpreter Lock (GIL) allows only one thread to execute Python bytecode at a time.

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

What is multiprocessing in Python?

A

It runs multiple processes, each with its own Python interpreter and memory. It bypasses the GIL.

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

When should you use multithreading?

A

Use it for I/O-bound tasks like network calls or file I/O.

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

When should you use multiprocessing?

A

Use it for CPU-bound tasks that need true parallel execution.

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

What is asynchronous programming?

A

A way to run tasks concurrently using async and await without blocking the main thread.

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

What module is used for asynchronous code?

A

Use the asyncio module for writing asynchronous programs.

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

How do you define an async function?

A

Use async def.

async def fetch_data():     return await get_data()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are await and async used for?

A

async marks a function as asynchronous, and await pauses until an async task completes.

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

Can you mix threading and asyncio?

A

Yes, but with care. Use loop.run_in_executor() to run blocking code in threads.

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