-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkill_all_jobs.py
More file actions
executable file
·42 lines (32 loc) · 1.09 KB
/
kill_all_jobs.py
File metadata and controls
executable file
·42 lines (32 loc) · 1.09 KB
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
#! /usr/bin/env python
from __future__ import print_function
from tempfile import mkstemp
import subprocess
from socket import gethostname
from os import remove
list_of_jobs_file_name = mkstemp()[1]
list_of_jobs_file = open(list_of_jobs_file_name, 'w')
print("Finding list of jobs to kill...")
subprocess.call(['nice', '-n', '19', 'JobShow.csh'],
stdout=list_of_jobs_file,
stderr=subprocess.STDOUT)
list_of_jobs_file.close();
list_of_jobs_file = open(list_of_jobs_file_name, 'r')
set_of_jobs_to_kill = set()
lines = list_of_jobs_file.readlines()
for line in lines:
words = line.split()
num_nums = 0
for word in words[0:4]:
if word.isdigit():
num_nums += 1
if num_nums == 4:
set_of_jobs_to_kill.add(words[0])
for job in set_of_jobs_to_kill:
print('Killing job #'+job+'...')
subprocess.Popen(['nice', '-n', '19', 'JobKill.csh', job])
if gethostname() == 'cms2.physics.ucsb.edu':
print('Cleaning up...')
subprocess.Popen(['nice', '-n', '19', 'JobCleanup.csh'])
list_of_jobs_file.close()
remove(list_of_jobs_file_name)