Skip to content

Instantly share code, notes, and snippets.

@meren
Created March 11, 2015 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meren/dbdef7adc18ea1b34048 to your computer and use it in GitHub Desktop.
Save meren/dbdef7adc18ea1b34048 to your computer and use it in GitHub Desktop.
Don't move to the next line in a batch operation until all jobs are done on the cluster, or, "poor man's hold"
import os
import sys
import time
import xml.dom.minidom
import string
import getpass
def still_running(job_name, job_owner):
f=os.popen('qstat -u \* -xml -r')
dom=xml.dom.minidom.parse(f)
jobs = dom.getElementsByTagName('job_info')
run = jobs[0]
joblist = run.getElementsByTagName('job_list')
for r in joblist:
job = r.getElementsByTagName('JB_name')[0].childNodes[0].data
owner = r.getElementsByTagName('JB_owner')[0].childNodes[0].data
if job == job_name and owner == job_owner:
return True
return False
job_owner = getpass.getuser()
job_name = sys.argv[1]
counter = 0
while still_running(job_name, job_owner):
time.sleep(5)
counter += 1
if counter == 11:
sys.stderr.write('.')
counter = 0
sys.stderr.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment