Concurrency & Multithreading Flashcards
7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Concurrency & Multithreading flashcards as text
What does setting thread.daemon = True do before starting a thread?
Answer: Makes the thread run in the background and automatically exit when the main program ends
Daemon threads are background threads that do not prevent the program from exiting; they are killed automatically when all non-daemon threads finish.
Which asyncio function is the standard entry point for running a top-level coroutine in Python 3.7+?
Answer: asyncio.run()
asyncio.run() creates a new event loop, runs the given coroutine until completion, and then closes the loop — it is the recommended entry point since Python 3.7.
What is a threading.Semaphore and how does it differ from a Lock?
Answer: A Semaphore maintains a counter allowing a configurable number of threads to access a resource concurrently, unlike a Lock which allows only one
A Semaphore(n) allows up to n threads to hold it simultaneously; a Lock is equivalent to a Semaphore(1), permitting only one thread at a time.
Which module provides the Process class for spawning separate OS processes in Python?
Answer: multiprocessing
The multiprocessing module's Process class creates true OS-level processes, each with its own Python interpreter and memory space, bypassing the GIL.
What is the purpose of threading.Event in Python multithreading?
Answer: To enable threads to signal each other — one thread sets the event, others wait for it
threading.Event provides wait(), set(), and clear() methods, allowing one thread to signal one or more waiting threads that a condition has occurred.
Which multiprocessing objects are used to share state (a single value or an array) safely between processes?
Answer: multiprocessing.Value and multiprocessing.Array
multiprocessing.Value and multiprocessing.Array store shared data in shared memory with built-in synchronization, accessible by multiple processes.
How does the GIL impact CPU-bound tasks in a multithreaded Python program?
Answer: It prevents threads from executing Python bytecode in parallel, so adding threads provides little or no speedup for CPU-bound work
Because the GIL serializes bytecode execution, CPU-bound multithreaded programs cannot truly run in parallel — use multiprocessing instead for CPU-bound parallelism.