def _wait_if_needed(arg_namespace, check_func, error_msg): if not arg_namespace.wait: return for path in arg_namespace.paths: file_ = File(path) timeout = arg_namespace.timeout time_started = time.time() while not check_func(file_): if time.time() - time_started > timeout: raise TimeoutError(error_msg) file_.update_info() time.sleep(0.1)