Прескочи на главни садржај
🔒 Режим прегледа. Првих петнаест Foundations лекција је бесплатно; ова је Pro. Покрените 7-дневни trial да откључате едитор, AI савете и остатак курса. Картица је обавезна, можете отказати у било ком тренутку у Dashboard.Покрени 7-дневни trial →
⚡
← Kursevi›Senior Deep-DivesModule 1 · Concurrency internals · Recap›

асинцио.ТаскГроуп (Питхон 3.11+) против окупљања

predict24 / 161
+125 XP
Zadatak🌐 shown in EN
📝 **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.
Predvidi izlaz

Pažljivo pročitaj kod

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())

Šta će program ispisati? Napiši ovde: