Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 1 · Concurrency internals · Recapasyncio.TaskGroup (Python 3.11+) vs gatherpredict24 / 161
+125 XP
Task
📝 **Question:** Predict the exact output. Three tasks start together: A finishes at t=0.01, B raises ValueError at t=0.05, C would finish at t=0.10. What happens to C when B raises? How many exceptions land in the \`except*\` group? 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Predict the output

Read the code carefully

import asyncio


async def task(name, delay, fail=False):
    await asyncio.sleep(delay)
    if fail:
        print(f"raise:{name}")
        raise ValueError(name)
    print(f"done:{name}")


async def main():
    try:
        async with asyncio.TaskGroup() as tg:
            tg.create_task(task("A", 0.01))
            tg.create_task(task("B", 0.05, fail=True))
            tg.create_task(task("C", 0.10))
    except* ValueError as eg:
        print(f"caught:{len(eg.exceptions)}")
    print("after")


asyncio.run(main())

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…