python from contexts import contextmanager @contextmanager def my_context(): setup_context() try: yield finally: cleanup_context() python with my_context(): do_something()