def METHOD_NAME(self, max_templates):
    try:
        was_capped = self.currently_capped
        self.currently_capped = True
        self.marker = max_templates
        yield
    finally:
        self.currently_capped = was_capped