Přejít k hlavnímu obsahu
🔒 Režim náhledu. Prvních patnáct lekcí Foundations je zdarma; tato je Pro. Spusťte 7denní trial pro odemčení editoru, AI nápověd a zbytku kurzu. Karta vyžadována, zrušte kdykoli v Dashboard.Spustit 7denní trial →
← KurzySenior Deep-DivesModule 1 · Concurrency internals · RecapVzory zrušení v asynciopredict25 / 161
+125 XP
Úkol🌐 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.
Předpověz výstup

Přečti kód pozorně

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

Co program vypíše? Napiš sem: