Zum Hauptinhalt springen
🔒 Vorschaumodus. Die ersten fünfzehn Foundations-Lektionen sind kostenlos; diese hier ist Pro. Starte einen 7-Tage-Trial, um den Editor, AI-Hinweise und den Rest des Lehrplans freizuschalten. Karte erforderlich, jederzeit im Dashboard kündbar.7-Tage-Trial starten →
← KurseSenior Deep-DivesModule 1 · Concurrency internals · RecapStornierungsmuster in Asynciopredict25 / 161
+125 XP
Aufgabe🌐 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.
Sage die Ausgabe vorher

Lies den Code sorgfältig

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

Was wird das Programm ausgeben? Schreib hier: