Concurrency and Async
Threads, processes and asyncio: what the GIL really does, how to run hundreds of LLM calls at once, and how to choose the right tool without guessing.
A program that does one thing at a time wastes most of its life waiting: for a web server, a database, a disk, an AI model. This phase teaches the three ways Python can do more than one thing at once (threads, processes and asyncio), what each one costs, and how to choose between them.
asyncio is the heart of the phase, and it runs live on this page. You will write coroutines, run them together with gather and TaskGroup, limit them with a Semaphore, stop them with timeouts, and stream fake model tokens with an async generator. This is exactly the shape of code that calls LLM APIs in production.
Threads and processes cannot start inside a web page, so those topics show real programs that were run on a normal Python, plus live examples of everything around them that does run here (locks, queues, futures, pickling). The phase ends with a decision guide and a debugging checklist.
Practise this phase
Hands-on exercises: write the code, run it, and press Check to have it tested automatically.