Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Defaults to 5.
**kwargs : :obj:`dict`
Additional keyword arguments will be passed to the chosen submission template according to `computing_configuration`.
Pass for example: jobname="job", cores=2, mem=8000, partition="longq".
"""
import time
import subprocess
import divvy
from ngs_toolkit import _CONFIG, _LOGGER
# reduce level of logging from divvy
# only for divvy <=0.
if "logging" in divvy.__dict__.keys():
divvy.logging.getLogger("divvy").setLevel("ERROR")
def count_jobs_running(check_cmd="squeue", sep="\n"):
"""
Count running jobs on a cluster by invoquing a command that lists the jobs.
"""
return subprocess.check_output(check_cmd).split(sep).__len__()
def submit_job_if_possible(
cmd, check_cmd="squeue", total_job_lim=800, refresh_time=10, in_between_time=5
):
submit = count_jobs_running(check_cmd) < total_job_lim
while not submit:
time.sleep(refresh_time)
submit = count_jobs_running(check_cmd) < total_job_lim
subprocess.call(cmd)
time.sleep(in_between_time)