def check_qsub_job_status(job_id, desired_status = "r"):
'''
Use 'qstat' to check on the run status of a qsub job
returns True or False if the job status matches the desired_status
job running:
desired_status = "r"
job waiting:
desired_status = "qw"
'''
import re
from sh import qstat
job_id_pattern = r"^.*{0}.*\s{1}\s.*$".format(job_id, desired_status)
# using the 'sh' package
qstat_stdout = qstat()
# using the standard subprocess package
# qstat_stdout = subprocess_cmd('qstat', return_stdout = True)
job_match = re.findall(str(job_id_pattern), str(qstat_stdout), re.MULTILINE)
job_status = bool(job_match)
if job_status == True:
status = True
return(job_status)
elif job_status == False:
return(job_status)
评论列表
文章目录