forked from AurelienNioche/SpatialMoney
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kill_jobs.py
47 lines (29 loc) · 1.01 KB
/
kill_jobs.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
from subprocess import check_output, CalledProcessError
import json
from arborescence.arborescence import Folders
class JobKiller(object):
def __init__(self):
self.folder = Folders.folders
def load_job_names(self):
with open("{}/job_names.json".format(self.folder["job_names"]), "r") as f:
job_names = json.load(f)
return job_names
@classmethod
def kill_jobs(cls, job_names):
for i in job_names:
command = "qdel {}".format(i)
print("Ask system '{}'".format(command))
try:
output = check_output(command.split())
output = str(output)[:-2] # [:-2] is for removing the \n at the end
print("System answers '{}'".format(output))
except CalledProcessError as e:
print(e)
def run(self):
job_names = self.load_job_names()
self.kill_jobs(job_names)
def main():
j = JobKiller()
j.run()
if __name__ == "__main__":
main()