Przejdź do treści głównej
🔒 Tryb podglądu. Pierwszych piętnaście lekcji Foundations jest darmowych; ta jest Pro. Rozpocznij 7-dniowy trial, aby odblokować edytor, podpowiedzi AI i resztę kursu. Wymagana karta, anulujesz w dowolnym momencie w Dashboard.Rozpocznij 7-dniowy trial →
← KursySenior Deep-DivesModule 1 · Concurrency internals · RecapExitStack do dynamicznego zarządzania kontekstempredict23 / 161
+100 XP
Zadanie🌐 shown in EN
📝 **Question:** Predict the exact output. \`res(name)\` is a tiny context manager that prints \`open:\` / \`close:\`. Three resources enter an \`ExitStack\` in order A → B → C. When the \`with\` exits, what order do they close in? 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Przewiduj wynik

Przeczytaj kod uważnie

from contextlib import ExitStack, contextmanager


@contextmanager
def res(name):
    print(f"open:{name}")
    try:
        yield name
    finally:
        print(f"close:{name}")


with ExitStack() as stack:
    a = stack.enter_context(res("A"))
    b = stack.enter_context(res("B"))
    c = stack.enter_context(res("C"))
    print(f"use:{a}{b}{c}")

print("done")

Co wypisze program? Napisz tutaj: