Using Python's ExitStack to mimic move semantics and make your own exception-safe context managers Python context managers make cleanup much easier, but they aren't easy to conditionally disable. Writing your own context managers can also be messy. ExitStack can solve both of these problems.