What is Python's threading module?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
The threading module provides thread-based concurrency. Create a thread: t = threading.Thread(target=my_function, args=(arg1,)). Start it: t.start(). Wait for completion: t.join(). Due to the GIL, Python threads are best for I/O-bound tasks (network requests, file I/O). Thread safety: use threading.Lock() to protect shared state: with lock: counter += 1. threading.Event for signaling between threads. threading.Semaphore for limiting concurrent access. threading.local() for thread-local storage. ThreadPoolExecutor from concurrent.futures manages a pool of threads: with ThreadPoolExecutor(max_workers=10) as executor: results = executor.map(fetch_url, urls). This is the modern, recommended way to do concurrent I/O in Python.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.