Example #1
0
def ipython_qstat(self, arg):
    """ Prints jobs of current user. """
    from subprocess import Popen, PIPE
    from IPython.utils.text import SList
    from itertools import chain
    # get user jobs ids
    whoami = Popen(['whoami'], stdout=PIPE).communicate()[0].rstrip().lstrip()
    jobs = Popen(['qstat', '-u', whoami],
                 stdout=PIPE).communicate()[0].split('\n')
    if len(jobs) == 1: return
    ids = SList(jobs[5:-1]).fields(0)
    # now gets full info
    jobs = SList(
        Popen(['qstat', '-f'] + ids, stdout=PIPE).communicate()[0].split('\n'))
    names = [
        u[u.find('=') + 1:].lstrip().rstrip() for u in jobs.grep('Job_Name')
    ]
    mpps = [int(u[u.find('=') + 1:]) for u in jobs.grep('Resource_List.ncpus')]
    states = [
        u[u.find('=') + 1:].lstrip().rstrip() for u in jobs.grep('job_state')
    ]
    ids = [u[u.find(':') + 1:].lstrip().rstrip() for u in jobs.grep('Job Id')]
    # the result is then  synthesized, with the first field the job id, and the
    # last the job name. This is important since it will be used by cancel as such.
    return SList([ "{0:>10} {1:>4} {2:>3} -- {3}".format(id, mpp, state, name)   \
                   for id, mpp, state, name in zip(ids, mpps, states, names)])
Example #2
0
def ipython_qstat(self, arg):
  """ Prints jobs of current user. """
  from subprocess import Popen, PIPE
  from IPython.utils.text import SList
  from itertools import chain
  # get user jobs ids
  whoami = Popen(['whoami'], stdout=PIPE).communicate()[0].rstrip().lstrip()
  jobs   = Popen(['qstat', '-u', whoami], stdout=PIPE).communicate()[0].split('\n')
  if len(jobs) == 1: return
  ids    = SList(jobs[5:-1]).fields(0)
  # now gets full info
  jobs   = SList(Popen(['qstat', '-f'] + ids, stdout=PIPE).communicate()[0].split('\n'))
  names  = [u[u.find('=')+1:].lstrip().rstrip() for u in jobs.grep('Job_Name')]
  mpps   = [int(u[u.find('=')+1:]) for u in jobs.grep('Resource_List.ncpus')]
  states = [u[u.find('=')+1:].lstrip().rstrip() for u in jobs.grep('job_state')]
  ids    = [u[u.find(':')+1:].lstrip().rstrip() for u in jobs.grep('Job Id')]
  # the result is then  synthesized, with the first field the job id, and the
  # last the job name. This is important since it will be used by cancel as such.
  return SList([ "{0:>10} {1:>4} {2:>3} -- {3}".format(id, mpp, state, name)   \
                 for id, mpp, state, name in zip(ids, mpps, states, names)])