Skip to content

Instantly share code, notes, and snippets.

@braingineer
Last active May 27, 2016 03:35
Show Gist options
  • Save braingineer/d3f5118edec7048a3f8a6116fb22b694 to your computer and use it in GitHub Desktop.
Save braingineer/d3f5118edec7048a3f8a6116fb22b694 to your computer and use it in GitHub Desktop.
valar morprocess
'''
super ugly. but works.
'''
import subprocess
import time
while True:
ps = subprocess.Popen(['qstat'], stdout=subprocess.PIPE).communicate()[0]
jid = int(ps.split("\n")[2].split(" ")[0])
ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0]
processes = ps.split('\n')
nfields = len(processes[0].split()) - 1
jobs = []
for row in processes[1:]:
if 'bcm84' not in row: continue
if 'python cluster_driver.py' not in row: continue
row = row.split(None, nfields)
print("job: {}; {} memory".format(row[-1], row[3]))
jobs.append(row)
for job in jobs:
job = [float(job[3]), int(job[-1].split(" ")[-1])]
print("if i was going to kill: qdel {} -t {}".format(jid, job[1]))
if job[0] > 20:
print("and to be fair.. {} should die".format(job[1]))
if raw_input("should i do it? (y/n)")=="y":
subprocess.Popen(['qdel {} -t {}'.format(jid, job[1])])
print("I've done it!.. i think")
time.sleep(10)
import subprocess
import time
import sys
num_killed = 0
num_iter = 0
while True:
num_iter += 1
ps = subprocess.Popen(['qstat'], stdout=subprocess.PIPE).communicate()[0]
jid = int(ps.split("\n")[2].split(" ")[0])
ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0]
processes = ps.split('\n')
nfields = len(processes[0].split()) - 1
jobs = []
for row in processes[1:]:
if 'bcm84' not in row: continue
if 'python cluster_driver.py' not in row: continue
row = row.split(None, nfields)
#print("job: {}; {} memory".format(row[-1], row[3]))
jobs.append(row)
for job in jobs:
job = [float(job[3]), int(job[-1].split(" ")[-1])]
#print("if i was going to kill: qdel {} -t {}".format(jid, job[1]))
if job[0] > 7.5:
#print("and to be fair.. {} should die".format(job[1]))
#if raw_input("should i do it? (y/n)")=="y":
subprocess.Popen('qdel {} -t {}'.format(jid, job[1]).split(" "))
#print("I've done it!.. i think")
num_killed += 1
sys.stdout.write("\rrunning... %d iterations; %d killings" % (num_iter, num_killed))
sys.stdout.flush()
time.sleep(10)
#ps aux | grep 'python cluster_driver' | awk '/cluster_driver.py/ {print }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment