diff --git a/doc/conf.py b/doc/conf.py index e4304073..6c72f6ce 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -20,7 +20,7 @@ # -- Project information ----------------------------------------------------- project = "DPDispatcher" -copyright = "2020-%d, Deep Modeling" % date.today().year +copyright = f"2020-{date.today().year}, Deep Modeling" author = "DeepModeling" diff --git a/dpdispatcher/base_context.py b/dpdispatcher/base_context.py index 0935e845..4f9096ea 100644 --- a/dpdispatcher/base_context.py +++ b/dpdispatcher/base_context.py @@ -102,8 +102,7 @@ def block_checkcall(self, cmd, asynchronously=False) -> Tuple[Any, Any, Any]: exit_status, stdin, stdout, stderr = self.block_call(cmd) if exit_status != 0: raise RuntimeError( - "Get error code %d in calling %s with job: %s . message: %s" - % ( + "Get error code {} in calling {} with job: {} . message: {}".format( exit_status, cmd, self.submission.submission_hash, diff --git a/dpdispatcher/contexts/ssh_context.py b/dpdispatcher/contexts/ssh_context.py index 75314890..179e02fa 100644 --- a/dpdispatcher/contexts/ssh_context.py +++ b/dpdispatcher/contexts/ssh_context.py @@ -90,8 +90,7 @@ def ensure_alive(self, max_check=10, sleep_time=10): while not self._check_alive(): if count == max_check: raise RuntimeError( - "cannot connect ssh after %d failures at interval %d s" - % (max_check, sleep_time) + f"cannot connect ssh after {max_check} failures at interval {sleep_time} s" ) dlog.info("connection check failed, try to reconnect to " + self.hostname) self._setup_ssh() diff --git a/dpdispatcher/machines/JH_UniScheduler.py b/dpdispatcher/machines/JH_UniScheduler.py index 3987374c..8a247814 100644 --- a/dpdispatcher/machines/JH_UniScheduler.py +++ b/dpdispatcher/machines/JH_UniScheduler.py @@ -105,8 +105,7 @@ def check_status(self, job): elif ret != 0: # just retry when any unknown error raised. raise RetrySignal( - "Get error code %d in checking status with job: %s . message: %s" - % (ret, job.job_hash, err_str) + f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}" ) status_out = stdout.read().decode("utf-8").split("\n") if len(status_out) < 2: diff --git a/dpdispatcher/machines/distributed_shell.py b/dpdispatcher/machines/distributed_shell.py index 71066dca..f5e0962e 100644 --- a/dpdispatcher/machines/distributed_shell.py +++ b/dpdispatcher/machines/distributed_shell.py @@ -181,8 +181,7 @@ def do_submit(self, job): if ret != 0: err_str = stderr.decode("utf-8") raise RuntimeError( - "Command %s fails to execute, error message:%s\nreturn code %d\n" - % (cmd, err_str, ret) + f"Command {cmd} fails to execute, error message:{err_str}\nreturn code {ret}\n" ) job_id = int(stdout.decode("utf-8").strip()) @@ -200,8 +199,7 @@ def check_status(self, job): if ret != 0: err_str = stderr.decode("utf-8") raise RuntimeError( - "Command fails to execute, error message:%s\nreturn code %d\n" - % (err_str, ret) + f"Command fails to execute, error message:{err_str}\nreturn code {ret}\n" ) if_job_exists = bool(stdout.decode("utf-8").strip()) diff --git a/dpdispatcher/machines/lsf.py b/dpdispatcher/machines/lsf.py index 06920a4b..eb0e0549 100644 --- a/dpdispatcher/machines/lsf.py +++ b/dpdispatcher/machines/lsf.py @@ -129,8 +129,7 @@ def check_status(self, job): elif ret != 0: # just retry when any unknown error raised. raise RetrySignal( - "Get error code %d in checking status with job: %s . message: %s" - % (ret, job.job_hash, err_str) + f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}" ) status_out = stdout.read().decode("utf-8").split("\n") if len(status_out) < 2: diff --git a/dpdispatcher/machines/pbs.py b/dpdispatcher/machines/pbs.py index 50ca3c5f..a055c50c 100644 --- a/dpdispatcher/machines/pbs.py +++ b/dpdispatcher/machines/pbs.py @@ -87,8 +87,7 @@ def check_status(self, job): return JobStatus.terminated else: raise RuntimeError( - "status command %s fails to execute. erro info: %s return code %d" - % (command, err_str, ret) + f"status command {command} fails to execute. erro info: {err_str} return code {ret}" ) status_line = stdout.read().decode("utf-8").split("\n")[-2] status_word = status_line.split()[-2] @@ -138,8 +137,7 @@ def check_status(self, job): return JobStatus.terminated else: raise RuntimeError( - "status command %s fails to execute. erro info: %s return code %d" - % (command, err_str, ret) + f"status command {command} fails to execute. erro info: {err_str} return code {ret}" ) status_line = stdout.read().decode("utf-8").split("\n")[-2] status_word = status_line.split()[-2] diff --git a/dpdispatcher/machines/shell.py b/dpdispatcher/machines/shell.py index 76225813..babb1971 100644 --- a/dpdispatcher/machines/shell.py +++ b/dpdispatcher/machines/shell.py @@ -43,8 +43,7 @@ def do_submit(self, job): if ret != 0: err_str = stderr.read().decode("utf-8") raise RuntimeError( - "status command %s fails to execute\nerror message:%s\nreturn code %d\n" - % (cmd, err_str, ret) + f"status command {cmd} fails to execute\nerror message:{err_str}\nreturn code {ret}\n" ) job_id = int(stdout.read().decode("utf-8").strip()) self.context.write_file(job_id_name, str(job_id)) @@ -80,8 +79,7 @@ def check_status(self, job): if ret != 0: err_str = stderr.read().decode("utf-8") raise RuntimeError( - "status command %s fails to execute\nerror message:%s\nreturn code %d\n" - % (cmd, err_str, ret) + f"status command {cmd} fails to execute\nerror message:{err_str}\nreturn code {ret}\n" ) if_job_exists = bool(stdout.read().decode("utf-8").strip()) diff --git a/dpdispatcher/machines/slurm.py b/dpdispatcher/machines/slurm.py index 951c0e45..710c2447 100644 --- a/dpdispatcher/machines/slurm.py +++ b/dpdispatcher/machines/slurm.py @@ -97,8 +97,7 @@ def do_submit(self, job): ): # server network error, retry 3 times raise RetrySignal( - "Get error code %d in submitting with job: %s . message: %s" - % (ret, job.job_hash, err_str) + f"Get error code {ret} in submitting with job: {job.job_hash} . message: {err_str}" ) elif ( "Job violates accounting/QOS policy" in err_str @@ -109,8 +108,7 @@ def do_submit(self, job): # job number exceeds, skip the submitting return "" raise RuntimeError( - "command %s fails to execute\nerror message:%s\nreturn code %d\n" - % (command, err_str, ret) + f"command {command} fails to execute\nerror message:{err_str}\nreturn code {ret}\n" ) subret = stdout.readlines() # --parsable @@ -145,13 +143,11 @@ def check_status(self, job): ): # retry 3 times raise RetrySignal( - "Get error code %d in checking status with job: %s . message: %s" - % (ret, job.job_hash, err_str) + f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}" ) raise RuntimeError( - "status command %s fails to execute." - "job_id:%s \n error message:%s\n return code %d\n" - % (command, job_id, err_str, ret) + f"status command {command} fails to execute." + f"job_id:{job_id} \n error message:{err_str}\n return code {ret}\n" ) status_line = stdout.read().decode("utf-8").split("\n")[-2] status_word = status_line.split()[-1] @@ -255,7 +251,7 @@ def gen_script_header(self, job): return super().gen_script_header(job) + "\n#SBATCH --array={}".format( ",".join(map(str, job_array)) ) - return super().gen_script_header(job) + "\n#SBATCH --array=0-%d" % ( + return super().gen_script_header(job) + "\n#SBATCH --array=0-%s" % ( math.ceil(len(job.job_task_list) / slurm_job_size) - 1 ) @@ -333,13 +329,11 @@ def check_status(self, job): ): # retry 3 times raise RetrySignal( - "Get error code %d in checking status with job: %s . message: %s" - % (ret, job.job_hash, err_str) + f"Get error code {ret} in checking status with job: {job.job_hash} . message: {err_str}" ) raise RuntimeError( - "status command %s fails to execute." - "job_id:%s \n error message:%s\n return code %d\n" - % (command, job_id, err_str, ret) + f"status command {command} fails to execute." + f"job_id:{job_id} \n error message:{err_str}\n return code {ret}\n" ) status_lines = stdout.read().decode("utf-8").split("\n")[:-1] status = [] diff --git a/dpdispatcher/utils/utils.py b/dpdispatcher/utils/utils.py index cec28f54..33f586cd 100644 --- a/dpdispatcher/utils/utils.py +++ b/dpdispatcher/utils/utils.py @@ -191,7 +191,7 @@ def wrapper(*args, **kwargs): else: # raise all exceptions raise RuntimeError( - "Failed to run %s for %d times" % (func.__name__, current_retry) + f"Failed to run {func.__name__} for {current_retry} times" ) from errors[-1] return wrapper