Capture the current context and apply it to the provided func

def with_current_context(self, func):
        """Capture the current context and apply it to the provided func"""

        caller_context = self.snapshot()

        def call_with_current_context(*args, **kwargs):
            try:
                backup_context = self.snapshot()
                self.apply(caller_context)
                return func(*args, **kwargs)
            finally:
                self.apply(backup_context)

        return call_with_current_context