Example #1
0
def qstat(jid):
    """ Check job status """
    s = Shell()
    rc, out, m = s.cmd1("qstat %s | grep %s | awk '{print $5}'" % (jid, jid))
    if rc != 0:
        return None
    return out.strip('\n')
Example #2
0
def qsubfeval(func, *vargs, **kwargs):
    """ Run the feval via a job on the Torque cluster. """

    global _batchId

    out = {'job': {'name': None, 'outputPkl': None, 'jid': None}}

    _validateInput(func, *vargs)
    _sid, _sPathPkl = _dumpSession(None if 'name' not in
                                   kwargs.keys() else kwargs['name'])
    _jName, _jInputPkl = _dumpJobData(_sid, 1, *vargs)
    _jobParams = _prepareJobScript(_sid, _sPathPkl, _jName, _jInputPkl, func)
    _s = Shell()

    if 'req' not in kwargs.keys():
        kwargs['req'] = {'walltime': '00:10:00', 'mem': '1gb'}

    _req = ','.join(
        map(lambda k: "%s=%s" % (k, kwargs['req'][k]), kwargs['req'].keys()))

    _cmd = 'echo "cd %s; which python; python %s; rm -f %s" | qsub -N %s -l "%s"' % (
        os.getcwd(), _jobParams['JOB_SCRIPT_PATH'],
        _jobParams['JOB_SCRIPT_PATH'], _jobParams['JOB_NAME'], _req)

    # returned values is a tuple of (rc, out, m) where
    # - rc: the command-line exit code
    # - out: the command-line output after execution
    # - m: the shell message involking the command
    rc, out, m = _s.cmd1(_cmd, timeout=5)
    _batchId += 1

    if rc != 0:
        return None

    _jobParams['JOB_ID'] = out.strip('\n')
    return _jobParams