Prejsť na hlavný obsah
🔒 Režim náhľadu. Prvých pätnásť lekcií Foundations je zadarmo; táto je Pro. Spustite 7-dňový trial pre odomknutie editora, AI nápovied a zvyšku kurzu. Karta vyžadovaná, zrušte kedykoľvek v Dashboard.Spustiť 7-dňový trial →
← KurzySenior Deep-DivesModule 1 · Concurrency internals · RecapVzory zrušenia v asynciopredict25 / 161
+125 XP
Úloha🌐 shown in EN
📝 **Question:** Predict the exact output. \`worker\` prints \`start\`, then awaits a long sleep. Main cancels the task. Trace: which prints fire, in what order? 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Predpovedz výstup

Prečítaj kód pozorne

import asyncio


async def worker():
    try:
        print("start")
        await asyncio.sleep(10)
        print("never")
    except asyncio.CancelledError:
        print("cleanup")
        raise


async def main():
    t = asyncio.create_task(worker())
    await asyncio.sleep(0)
    t.cancel()
    try:
        await t
    except asyncio.CancelledError:
        print("caught")
    print("after")


asyncio.run(main())

Čo program vypíše? Napíš sem: