Two waits: one after another, then together
Watch the order of the lines. In the second half both jobs start before either finishes.
Concurrency means several tasks are in progress at once, even if only one runs at any instant; parallelism means several really run at the same instant. Python gives you three tools (threads, processes and asyncio), and the right one depends on whether your program mostly waits (I/O-bound) or mostly calculates (CPU-bound).
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Classify each as I/O-bound or CPU-bound: (a) downloading 50 PDFs, (b) computing the 35th Fibonacci number with recursion, (c) reading 10,000 rows from a database over the network.
Using asyncio.gather, run three coroutines a, b, c that sleep 0.03, 0.01 and 0.02 seconds, and print their names in the order they finish.
Write a function choose(job) that returns "asyncio" when job is "many api calls", "processes" when it is "heavy maths", and "no concurrency" otherwise.
Explain it without notes
What is the difference between concurrency and parallelism? Which does asyncio give you?
What is the difference between I/O-bound and CPU-bound work? Give one AI-related example of each.
Why is asyncio called cooperative, and what is the danger of that?
A script calls an LLM API 500 times, one after another, and takes ten minutes. What would you change, and why does it work?
Expected output
--- one after another ---
kettle: start
kettle: done
toaster: start
toaster: done
--- together ---
kettle: start
toaster: start
toaster: done
kettle: done
results: ['kettle', 'toaster']