def handle(self, *args, **options): try: # before starting to repair the storage folder, make sure to lock # the storage so that any other processes with heavy/frequent # operations on the storage don't get in our way lock = Lock('storage') lock.acquire() repair_storage_folder() finally: lock.release()