-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCancelJobs.py
77 lines (66 loc) · 2.78 KB
/
CancelJobs.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'''
********************** Script to Cancel the Jobs on Clusters ********************
* Author: Muhammad Junaid Aslam
* Contact: [email protected]
* ---------------------------------------------------------------------
* This software is governed by the No license. You can use, modify |
* and redistribute the software under the condition of citing |
* or crediting the authors of this software in your work. |
* ---------------------------------------------------------------------
*
* This was part of a research project funded by the EWI EEMCS Group of
* Technical University of Delft, Netherlands.
**********************************************************************************
'''
import subprocess
import argparse
def run_command(incommand):
p = subprocess.Popen(incommand.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
outstring = p.stdout.read()
return outstring
def parse_args():
parser = argparse.ArgumentParser(description="Create task sets file")
parser.add_argument('-j', '--Job_ID', dest='Job_ID', default='Null',
action='store', type=str, metavar="JOB ID TO CANCEL",
required=False,
help='Provide Job_ID to Cancel, otherwise all jobs will be canceled')
parser.add_argument('-i', '--Most_Significant_Number', dest='MSN', default='Null',
action='store', type=str, metavar="MOST SIGNIFICANT NUM",
required=False,
help='Most Significant Number to Identify all Job IDs in case of Cancelling ALL IDs')
return parser.parse_args()
def run_command(incommand):
p = subprocess.Popen(incommand.split(), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
outstring = p.stdout.read()
return outstring
def CancelAllJobs(MSD):
lvCMD = 'squeue -u jaslam'
Result = run_command(lvCMD)
encoding = 'utf-8'
lvResults = str(Result, encoding)
AllIDs = lvResults.split(' ')
for row in range(0, len(AllIDs)):
if str(MSD) in AllIDs[row]:
if int(AllIDs[row]) > (int(MSD)*10000):
#print("ID:%d"%int(AllIDs[row]))
lvCMD = "scancel "+(AllIDs[row])
print(run_command(lvCMD))
def CancelInputJobs(JobIDs):
lvIDs = JobIDs.split(' ')
for n in range(0, len(lvIDs)):
lvCMD = "scancel "+lvIDs[n]
print(run_command(lvCMD))
def main():
opts = parse_args()
JobIDs = opts.Job_ID
MSD = opts.MSN
if MSD != "Null":
CancelAllJobs(MSD)
elif JobIDs != "Null":
CancelInputJobs(JobIDs)
else:
print("Enter either JobIDs or common Most Significant 2 or 3 Digits of submitted jobs to cancel all jobs at once")
if __name__ == '__main__':
main()