Skip to content
Preptima

Concurrency & the GIL interview questions

Threads versus processes versus asyncio, what the GIL actually blocks, and choosing per workload.

4 questions in Python.

medium2

hard2

hardConceptScenario

An asyncio call times out and you handle the TimeoutError, but the background task keeps running and mutates shared state a few seconds later. What happened, and how do you make the timeout actually stop the work?

A timeout requests cancellation; it does not stop code. CancelledError is raised at the task next await point, so a task inside blocking code, shielded, in an executor thread, or swallowing the exception keeps running and commits its side effects late. Fix by re-raising CancelledError, keeping blocking calls off the loop, and using asyncio.timeout with a TaskGroup.

4 minmid, senior, staff