Query equivalent to "sacct --state=XYZ"

38 views
Skip to first unread message

cco...@nvidia.com

unread,
Apr 3, 2019, 4:42:40 PM4/3/19
to pyslurm
I've been using the  pyslurm.slurmdb_jobs interface as a way to get non-active job information the away I usually would from the sacct command. However, I don't immediately see a state property in the job information that's returned. That is, I want to do something equivalent to:

sacct --state=XYZ

where XYZ coudl be CANCELLED, COMPLETED, FAILED or any of the other slurm job state codes. Basically, I want to search in completed jobs by termination status, not just the job exit code itself (which I do see in the job info returned by the slurmdb API).

Is there currently a way to do this? 

Thanks!


Terry Jones

unread,
Apr 3, 2019, 6:33:08 PM4/3/19
to cco...@nvidia.com, pyslurm
I don't know what the answer is in pyslurm, but I wrote some sacct code that might help you. It provides an SAcct class that you pass a list of job ids to, and an optional list of fields you want back from the sacct call. Then you have easy access to those fields, with some provided convenience methods:

from slurm_pipeline.sacct import SAcct

sa = SAcct((12345, 23456, 34567))

if sa.failed(12345):
    # Etc

if sa.state(23456) == 'COMPLETED':
    # Etc

See https://github.com/acorg/slurm-pipeline/blob/master/slurm_pipeline/sacct.py    (note that I just updated that to remove an unused argument).

Terry


--
You received this message because you are subscribed to the Google Groups "pyslurm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyslurm+u...@googlegroups.com.
To post to this group, send email to pys...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyslurm/079e7a5f-df3f-443f-8627-e6dccdd9bbf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cco...@nvidia.com

unread,
Apr 4, 2019, 9:52:32 AM4/4/19
to pyslurm
So it seems like there is a "state" field but it's populated numerically. I suppose I now just need to find the mapping of numeric codes to states.

Giovanni

unread,
Apr 7, 2019, 2:13:10 PM4/7/19
to pyslurm


On Wednesday, April 3, 2019 at 4:42:40 PM UTC-4, cco...@nvidia.com wrote:
Currently, the interface to retrieve jobs using this class doesn't let you filter by state.  However, the job info reported by pyslurm.slurmdb_jobs().get() does return the state, albeit as a numerical string.  I just pushed a change to the 18.08.0 branch.  This function will now return a 'state_str' parameter for the job: https://github.com/PySlurm/pyslurm/commit/779fcf9835b6aec5e607363f95986f9f88d6b4c4.  You can use this, or the numerical state, to filter job states when iterating over a list of returned jobs.

Giovanni

cco...@nvidia.com

unread,
Apr 9, 2019, 12:47:58 PM4/9/19
to pyslurm
That's great! Thanks!
Reply all
Reply to author
Forward
0 new messages