What is the difference between a coroutine object and a running task?
Understand the idea, explain it in your own words and use the rubric to find your next learning gap.
The idea behind the question
Calling an async function creates a coroutine object; awaiting it or scheduling it drives execution. Task ownership determines who waits, cancels and observes failures.
A developer creates several async document requests but forgets to await them before the program exits.
import asyncio
async def work(name):
await asyncio.sleep(0)
return name
async def main():
tasks = [asyncio.create_task(work(name)) for name in ["research", "coding"]]
results = await asyncio.gather(*tasks)
print(results)
asyncio.run(main())Show expected output
['research', 'coding']Copy and paste to run in a separate tab. This example illustrates one concept; it is not a complete application or an automatically graded task.
A practical way to learn it
Run the task example and explain why the printed result order is not evidence of completion order. Then add a deliberate exception and inspect it.
Open Python playgroundThe related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.
Build an explanation you understand
- State what the concept does in plain language.
- Apply it to the example and make your assumptions explicit.
- Explain a trade-off, failure case and how you would test it.
- Distinguish your actual experience from a proposed approach.
How would you explain it?
Single-question timers reset on refresh. Full mock sessions can resume from this browser.
Strengthen your explanation
Compare reasoning, not identical wording. Reference answers describe a possible approach; replace hypothetical statements with truthful details from your own work.
One way to answer
I would distinguish declaring an async function, creating a coroutine and scheduling a task in a running event loop. I would keep an owner that awaits completion and handles errors and cancellation. I would choose gather or structured task management based on the required failure behavior, checking the Python version and the documented semantics. I would not assume gather cancels every sibling after one failure. I would also avoid swallowing cancellation exceptions and would release owned resources. Unobserved background tasks are not a reliable job queue or a persistence strategy.
What a strong explanation should cover
Tick only the points your own answer addresses. This is self-assessment, not AI scoring.
0 / 3 points self-reportedWatch out for
- Calling an async function without awaiting or scheduling its result.
Now go one level deeper
- What changes when one task raises?
- When does a workflow need a durable job queue instead?
Further reading
Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.