Defer in Python

Implementing Go's defer through ExitStack.