def new_func(self, request): # Get some info about the controller call info = inspect(self, request, lock_file_path) # create a ResourceFile object to manage volume ownership resource = ResourceFile(info['lock_file']) try: # Attempt to claim exclusive ownership of the volume claim(resource, info) # Execute the controller method return func(self, request, resource) finally: # Remove the resource file if we own it resource.remove()