def deleter_thread(exit_event):
    while (not exit_event.is_set()):
        out_of_bytes = (get_available_bytes(default=(MIN_BYTES + 1)) < MIN_BYTES)
        out_of_percent = (get_available_percent(default=(MIN_PERCENT + 1)) < MIN_PERCENT)
        if (out_of_percent or out_of_bytes):
            dirs = listdir_by_creation(ROOT)
            for delete_dir in dirs:
                delete_path = os.path.join(ROOT, delete_dir)
                if any((name.endswith('.lock') for name in os.listdir(delete_path))):
                    continue
                try:
                    cloudlog.info(('deleting %s' % delete_path))
                    shutil.rmtree(delete_path)
                    break
                except OSError:
                    cloudlog.exception(('issue deleting %s' % delete_path))
            exit_event.wait(0.1)
        else:
            exit_event.wait(30)
def deleter_thread(exit_event):
    while (not exit_event.is_set()):
        out_of_bytes = (get_available_bytes(default=(MIN_BYTES + 1)) < MIN_BYTES)
        out_of_percent = (get_available_percent(default=(MIN_PERCENT + 1)) < MIN_PERCENT)
        if (out_of_percent or out_of_bytes):
            dirs = listdir_by_creation(ROOT)
            for delete_dir in dirs:
                delete_path = os.path.join(ROOT, delete_dir)
                if any((name.endswith('.lock') for name in os.listdir(delete_path))):
                    continue
                try:
                    cloudlog.info(('deleting %s' % delete_path))
                    shutil.rmtree(delete_path)
                    break
                except OSError:
                    cloudlog.exception(('issue deleting %s' % delete_path))
            exit_event.wait(0.1)
        else:
            exit_event.wait(30)