Q1
When does Python's Global Interpreter Lock (GIL) NOT block parallel execution across CPU cores?
C-extension libraries like NumPy, PyTorch, zlib, and blocking I/O syscalls release the GIL while running native C code or OS waits. Pure Python CPU loops still require multiprocessing to utilize multiple cores.
Q2
Why should custom decorators always apply @functools.wraps(func)?
Without @wraps(func), the wrapper replaces the original function's __name__, __doc__, type annotations, and __wrapped__ metadata—breaking FastAPI dependency inspection, pytest fixtures, and Sphinx documentation.
Q3
Why does putting __slots__ = ('x', 'y') on classes with millions of instances dramatically reduce RAM?
Normal Python instances store attributes inside a per-object __dict__ hash table (~104+ bytes overhead each). __slots__ allocates a fixed-offset C-like slot array on the object header, skipping __dict__ entirely.
Q4
What subtle bug happens if an async def function calls time.sleep() or requests.get() inside an asyncio event loop?
Synchronous blocking calls freeze the single-threaded event loop across ALL concurrent coroutines. Use await asyncio.sleep() / httpx.AsyncClient, or offload blocking SDKs to await asyncio.to_thread(...).
Q5
Why do dataclasses forbid mutable defaults like tags: list[str] = [] and require field(default_factory=list)?
@dataclass enforces Python safety at class creation time by raising ValueError: mutable default so separate instances never accidentally share the exact same default list or dict.
Q6
How does Python's MRO (C3 Linearization) resolve diamond multiple inheritance cleanly?
C3 linearization builds a deterministic left-to-right, depth-first-before-shared-ancestor lookup order (Class.__mro__). Using super() consistently passes control along the full MRO chain instead of calling a single parent twice.
Q7
Why can weakref caches prevent Out-Of-Memory leaks inside long-running Python services?
WeakValueDictionary or weakref.ref holds object references without incrementing CPython's reference count—allowing garbage collection to reclaim cached objects automatically once active callers drop them.
Q8
What is the performance difference between ''.join(chunks) vs s += chunk inside a tight loop?
While CPython tries an in-place optimization when refcount is 1, any second reference forces quadratic O(n^2) string reallocation on every +=. ''.join(chunks) pre-calculates total byte length in one pass for guaranteed O(n) speed.
Q9
How do context managers created via @contextlib.contextmanager handle exceptions raised inside the with block?
The exception gets injected right at the yield point inside the generator. Wrapping yield in try ... finally guarantees DB locks, temp files, or sessions close reliably even on failure.
Q10
Why does multiprocessing require an if __name__ == '__main__': guard on Windows?
Windows lacks POSIX fork() and spawns fresh Python interpreters that re-import the main script module. Without __main__, each child recursively spawns new children indefinitely until the OS crashes.