-
Notifications
You must be signed in to change notification settings - Fork 12
/
submit.py
executable file
·58 lines (45 loc) · 1.64 KB
/
submit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
import sys
from subprocess import Popen, PIPE
from snakemake.utils import read_job_properties
from time import sleep
jobscript = sys.argv[-1]
dependencies = set(sys.argv[1:-1])
jobprops = read_job_properties(jobscript)
cmdline = ["sbatch"]
cmdline.append("--parsable")
if dependencies:
cmdline.append("--dependency")
cmdline.append( "afterok:" + ",".join(dependencies))
if jobprops["cluster"]:
if jobprops["cluster"]["time"]:
cmdline.append("--time=" + jobprops["cluster"]["time"])
if jobprops["cluster"]["partition"]:
cmdline.append("--partition=" + jobprops["cluster"]["partition"])
if jobprops["cluster"]["cpus"]:
cmdline.append("--cpus-per-task=" + jobprops["cluster"]["cpus"])
if jobprops["cluster"]["mem"]:
cmdline.append("--mem=" + jobprops["cluster"]["mem"])
if jobprops["cluster"]["jobname"]:
cmdline.append("--job-name=" + jobprops["cluster"]["jobname"])
if jobprops["cluster"]["output"]:
cmdline.append("--output=" + jobprops["cluster"]["output"])
if jobprops["cluster"]["error"]:
cmdline.append("--error=" + jobprops["cluster"]["error"])
cmdline.append(jobscript)
# Constructs and submits
#cmdline = " ".join(cmdline)
#out = open("1.txt", "a")
#out.write(" ".join(cmdline) + "\n")
#out.close()
sleepTime = 0.25
timeMultiplier = 4
for i in range(7):
submitOut = Popen(cmdline, stdout = PIPE, stderr = PIPE)
jobid, joberr = submitOut.communicate()
jobid = jobid.decode("utf-8")
if submitOut.returncode == 0:
print(jobid, end = "")
break
sleep(sleepTime)
sleepTime *= timeMultiplier