# slurm_script_generator.squeue

*module*

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1-L1)

## slurm_script_generator.squeue.ACTIVE_STATES

*attribute* · *module attribute*

```python
ACTIVE_STATES = {'R', 'PD', 'CG', 'CF', 'RQ', 'RS', 'SI', 'SO', 'ST', 'S', 'RH', 'RF'}
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L86-L86)

## slurm_script_generator.squeue.FAILED_JOB_STATES

*attribute* · *module attribute*

```python
FAILED_JOB_STATES = {'BOOT_FAIL', 'CANCELLED', 'DEADLINE', 'FAILED', 'NODE_FAIL', 'OUT_OF_MEMORY', 'PREEMPTED', 'REVOKED', 'TIMEOUT'}
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L91-L101)

## slurm_script_generator.squeue.JOB_STATES

*attribute* · *module attribute*

```python
JOB_STATES = {'BF': 'Boot Fail', 'CA': 'Cancelled', 'CD': 'Completed', 'CF': 'Configuring', 'CG': 'Completing', 'DL': 'Deadline', 'F': 'Failed', 'NF': 'Node Fail', 'OOM': 'Out of Memory', 'PD': 'Pending', 'PR': 'Preempted', 'R': 'Running', 'RD': 'Resv Del Hold', 'RF': 'Requeue Fed', 'RH': 'Requeue Hold', 'RQ': 'Requeued', 'RS': 'Resizing', 'RV': 'Revoked', 'SI': 'Signaling', 'SE': 'Special Exit', 'SO': 'Stage Out', 'ST': 'Stopped', 'S': 'Suspended', 'TO': 'Timeout'}
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L58-L83)

## slurm_script_generator.squeue.SAcct

*class*

```python
class SAcct
```

Interface to SLURM job accounting via ``sacct``.

Parameters
----------
user : str, optional
    If given, fetch only jobs for this user.
days : int
    Number of days of history to look back (default: 7).
partition : str, optional
    If given, filter to this partition.
me : bool
    If True, fetch only jobs belonging to the current OS user.
    Mutually exclusive with *user*. Defaults to False.

Examples
--------
>>> a = SAcct(user='alice', days=30)
>>> a.summary()
{'total': 42, 'completed': 30, 'failed': 5, ...}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1476-L1633)

### slurm_script_generator.squeue.SAcct.jobs

*method*

```python
def jobs(user: Optional[str] = None, state: Optional[str] = None, partition: Optional[str] = None) -> List[SAcctJob]
```

Return accounting records matching the given criteria.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1563-L1577)

### slurm_script_generator.squeue.SAcct.jobs_by_partition

*method*

```python
def jobs_by_partition() -> Dict[str, List[SAcctJob]]
```

Return a mapping of partition -> list of jobs in that partition.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1593-L1598)

### slurm_script_generator.squeue.SAcct.jobs_by_state

*method*

```python
def jobs_by_state() -> Dict[str, List[SAcctJob]]
```

Return a mapping of state -> list of jobs in that state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1586-L1591)

### slurm_script_generator.squeue.SAcct.jobs_by_user

*method*

```python
def jobs_by_user() -> Dict[str, List[SAcctJob]]
```

Return a mapping of username -> list of their historical jobs.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1579-L1584)

### slurm_script_generator.squeue.SAcct.refresh

*method*

```python
def refresh() -> SAcct
```

Re-run ``sacct`` and update the cached job list.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1511-L1561)

### slurm_script_generator.squeue.SAcct.summary

*method*

```python
def summary() -> dict
```

Return a summary dict of job counts and CPU usage.

Returns
-------
dict
    Keys: ``total``, ``completed``, ``failed``, ``cancelled``,
    ``timeout``, ``cpu_hours``, ``by_state``, ``users``.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1600-L1620)

## slurm_script_generator.squeue.SAcctJob

*class* · *dataclass*

```python
class SAcctJob
```

A single job record from SLURM accounting (``sacct``).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1434-L1473)

### slurm_script_generator.squeue.SAcctJob.cpu_time_raw

*attribute* · *instance attribute*

```python
cpu_time_raw: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1446-L1446)

### slurm_script_generator.squeue.SAcctJob.elapsed

*attribute* · *instance attribute*

```python
elapsed: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1445-L1445)

### slurm_script_generator.squeue.SAcctJob.exit_code

*attribute* · *instance attribute*

```python
exit_code: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1447-L1447)

### slurm_script_generator.squeue.SAcctJob.job_id

*attribute* · *instance attribute*

```python
job_id: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1438-L1438)

### slurm_script_generator.squeue.SAcctJob.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1440-L1440)

### slurm_script_generator.squeue.SAcctJob.num_cpus

*attribute* · *instance attribute*

```python
num_cpus: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1444-L1444)

### slurm_script_generator.squeue.SAcctJob.num_nodes

*attribute* · *instance attribute*

```python
num_nodes: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1443-L1443)

### slurm_script_generator.squeue.SAcctJob.partition

*attribute* · *instance attribute*

```python
partition: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1442-L1442)

### slurm_script_generator.squeue.SAcctJob.state

*attribute* · *instance attribute*

```python
state: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1441-L1441)

### slurm_script_generator.squeue.SAcctJob.user

*attribute* · *instance attribute*

```python
user: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1439-L1439)

### slurm_script_generator.squeue.SAcctJob.cpu_hours

*property*

```python
cpu_hours: float
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1450-L1451)

### slurm_script_generator.squeue.SAcctJob.is_cancelled

*property*

```python
is_cancelled: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1462-L1463)

### slurm_script_generator.squeue.SAcctJob.is_completed

*property*

```python
is_completed: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1454-L1455)

### slurm_script_generator.squeue.SAcctJob.is_failed

*property*

```python
is_failed: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1458-L1459)

### slurm_script_generator.squeue.SAcctJob.is_timeout

*property*

```python
is_timeout: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1466-L1467)

## slurm_script_generator.squeue.SQueue

*class*

```python
class SQueue
```

Interface to the SLURM job queue via ``squeue``.

Parameters
----------
user : str, optional
    If given, only fetch jobs belonging to this user by default.
me : bool
    If True, fetch only jobs belonging to the current OS user by default.
    Mutually exclusive with *user*. Defaults to False.

Examples
--------
>>> q = SQueue()
>>> q.summary()
{'total_jobs': 42, 'running': 30, 'pending': 12, 'users': {...}, 'by_state': {...}}

>>> q.wait_until_done(job_name='training_*')
>>> q.wait_until_done(job_id=12345)
>>> q.wait_until_done(job_id=[12345, 12346])
>>> q.wait_until_done(user='alice')

>>> q.cancel(job_id=12345)
>>> q.cancel(job_name='training_*')

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L541-L1078)

### slurm_script_generator.squeue.SQueue.cancel

*method*

```python
def cancel(job_name: Optional[str] = None, job_id: Optional[Union[int, str, List[Union[int, str]]]] = None, user: Optional[str] = None, state: Optional[str] = None, partition: Optional[str] = None, verbose: bool = True, me: bool = False) -> List[int]
```

Cancel all matching jobs with ``scancel``.

Supports glob patterns in *job_name* (``*`` and ``?`` wildcards).
At least one filter argument must be provided, so that an accidental
call cannot cancel the whole queue.

Parameters
----------
job_name : str, optional
    Job name or glob pattern, e.g. ``'train_*'``.
job_id : int, str, or list of int/str, optional
    A specific job ID, or a list of job IDs, to cancel.
user : str, optional
    Cancel all jobs belonging to this user.
me : bool
    Cancel all jobs belonging to the current OS user. Mutually
    exclusive with *user*. Defaults to False.
state : str, optional
    SLURM state code, e.g. ``'PD'`` to cancel only pending jobs.
partition : str, optional
    Partition name to filter by.
verbose : bool
    Print progress messages. Defaults to True.

Returns
-------
list of int
    The job IDs that were passed to ``scancel``.

Raises
------
ValueError
    If no filter is specified.
RuntimeError
    If ``scancel`` exits with a non-zero status.

Examples
--------
>>> q = SQueue()
>>> q.cancel(job_id=12345)
>>> q.cancel(job_name='train_*')
>>> q.cancel(user='alice', state='PD')

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L819-L909)

### slurm_script_generator.squeue.SQueue.jobs

*method*

```python
def jobs(job_name: Optional[str] = None, job_id: Optional[Union[int, str, List[Union[int, str]]]] = None, user: Optional[str] = None, state: Optional[str] = None, partition: Optional[str] = None, me: bool = False) -> List[SQueueJob]
```

Return jobs matching the given criteria.

Parameters
----------
job_name : str, optional
    Job name or glob pattern (e.g. ``'train_*'``).
job_id : int, str, or list of int/str, optional
    Exact job ID, or a list of job IDs.
user : str, optional
    Username to filter by.
state : str, optional
    SLURM state code, e.g. ``'R'`` or ``'PD'``.
partition : str, optional
    Partition name to filter by.
me : bool
    Filter to jobs belonging to the current OS user. Mutually
    exclusive with *user*. Defaults to False.

Returns
-------
list of SQueueJob

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L632-L678)

### slurm_script_generator.squeue.SQueue.jobs_by_partition

*method*

```python
def jobs_by_partition() -> Dict[str, List[SQueueJob]]
```

Return a mapping of partition name -> list of jobs in that partition.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L933-L938)

### slurm_script_generator.squeue.SQueue.jobs_by_state

*method*

```python
def jobs_by_state() -> Dict[str, List[SQueueJob]]
```

Return a mapping of state code -> list of jobs in that state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L926-L931)

### slurm_script_generator.squeue.SQueue.jobs_by_user

*method*

```python
def jobs_by_user() -> Dict[str, List[SQueueJob]]
```

Return a mapping of username -> list of their jobs.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L919-L924)

### slurm_script_generator.squeue.SQueue.pending_jobs

*method*

```python
def pending_jobs() -> List[SQueueJob]
```

Return all jobs currently in the PD (Pending) state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L684-L686)

### slurm_script_generator.squeue.SQueue.refresh

*method*

```python
def refresh() -> SQueue
```

Re-run ``squeue`` and update the cached job list.

Returns
-------
SQueue
    self, for chaining.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L582-L626)

### slurm_script_generator.squeue.SQueue.running_jobs

*method*

```python
def running_jobs() -> List[SQueueJob]
```

Return all jobs currently in the R (Running) state.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L680-L682)

### slurm_script_generator.squeue.SQueue.summary

*method*

```python
def summary() -> dict
```

Return a summary dict with total counts, per-user counts, and per-state counts.

Returns
-------
dict
    Keys: ``total_jobs``, ``running``, ``pending``,
    ``users`` (dict of user -> job count),
    ``by_state`` (dict of state code -> job count).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L940-L958)

### slurm_script_generator.squeue.SQueue.users

*method*

```python
def users() -> List[str]
```

Return a sorted list of unique users with jobs in the queue.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L915-L917)

### slurm_script_generator.squeue.SQueue.wait_until_done

*method*

```python
def wait_until_done(job_name: Optional[str] = None, job_id: Optional[Union[int, str, List[Union[int, str]]]] = None, user: Optional[str] = None, poll_interval: float = 30.0, timeout: Optional[float] = None, verbose: bool = True, check: bool = False, me: bool = False) -> Dict[int, Optional[str]]
```

Block until all matching jobs leave the active queue.

Supports glob patterns in *job_name* (``*`` and ``?`` wildcards).
At least one filter argument must be provided.

Once the jobs are gone the final states are looked up with a single
``sacct`` call (see :func:`job_states`), so the caller learns whether
the jobs it waited for actually succeeded.

Parameters
----------
job_name : str, optional
    Job name or glob pattern, e.g. ``'train_*'``.
job_id : int, str, or list of int/str, optional
    A specific job ID, or a list of job IDs, to wait for.
user : str, optional
    Wait for all jobs belonging to this user to finish.
me : bool
    Wait for all jobs belonging to the current OS user. Mutually
    exclusive with *user*. Defaults to False.
poll_interval : float
    Seconds between queue polls. Defaults to 30.
timeout : float, optional
    Maximum seconds to wait before raising ``TimeoutError``.
verbose : bool
    Print progress messages. Defaults to True.
check : bool
    Raise ``RuntimeError`` if any job ended in a state from
    :data:`FAILED_JOB_STATES`. Jobs whose state is undetermined
    (None) never trigger this. Defaults to False.

Returns
-------
dict of int -> (str or None)
    Final accounting state per job ID that was waited on. A None value
    means the state could not be determined, not that the job failed.

Raises
------
ValueError
    If no filter is specified.
TimeoutError
    If *timeout* is exceeded before all jobs finish.
RuntimeError
    If *check* is True and a job ended in a failure state.

Examples
--------
>>> q.wait_until_done(job_id=12345)
{12345: 'COMPLETED'}
>>> q.wait_until_done(job_name='train_*', check=True)
{12345: 'COMPLETED', 12346: 'COMPLETED'}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L712-L813)

## slurm_script_generator.squeue.SQueueJob

*class* · *dataclass*

```python
class SQueueJob
```

A single job entry from the SLURM queue.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L379-L486)

### slurm_script_generator.squeue.SQueueJob.job_id

*attribute* · *instance attribute*

```python
job_id: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L383-L383)

### slurm_script_generator.squeue.SQueueJob.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L385-L385)

### slurm_script_generator.squeue.SQueueJob.num_cpus

*attribute* · *instance attribute*

```python
num_cpus: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L389-L389)

### slurm_script_generator.squeue.SQueueJob.num_nodes

*attribute* · *instance attribute*

```python
num_nodes: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L388-L388)

### slurm_script_generator.squeue.SQueueJob.partition

*attribute* · *instance attribute*

```python
partition: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L387-L387)

### slurm_script_generator.squeue.SQueueJob.priority

*attribute* · *instance attribute*

```python
priority: int
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L393-L393)

### slurm_script_generator.squeue.SQueueJob.reason

*attribute* · *instance attribute*

```python
reason: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L392-L392)

### slurm_script_generator.squeue.SQueueJob.state

*attribute* · *instance attribute*

```python
state: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L386-L386)

### slurm_script_generator.squeue.SQueueJob.submit_time

*attribute* · *class attribute* · *instance attribute*

```python
submit_time: str = ''
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L394-L394)

### slurm_script_generator.squeue.SQueueJob.time_limit

*attribute* · *instance attribute*

```python
time_limit: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L391-L391)

### slurm_script_generator.squeue.SQueueJob.time_used

*attribute* · *instance attribute*

```python
time_used: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L390-L390)

### slurm_script_generator.squeue.SQueueJob.user

*attribute* · *instance attribute*

```python
user: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L384-L384)

### slurm_script_generator.squeue.SQueueJob.is_active

*property*

```python
is_active: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L405-L406)

### slurm_script_generator.squeue.SQueueJob.is_pending

*property*

```python
is_pending: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L401-L402)

### slurm_script_generator.squeue.SQueueJob.is_running

*property*

```python
is_running: bool
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L397-L398)

### slurm_script_generator.squeue.SQueueJob.state_name

*property*

```python
state_name: str
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L409-L410)

### slurm_script_generator.squeue.SQueueJob.submit_datetime

*property*

```python
submit_datetime: Optional[datetime]
```

The job's submission time, or None if squeue didn't report one.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L413-L415)

### slurm_script_generator.squeue.SQueueJob.waiting_seconds

*property*

```python
waiting_seconds: Optional[float]
```

Seconds elapsed since submission — how long a pending job has waited.

None when the submission time could not be determined.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L418-L426)

### slurm_script_generator.squeue.SQueueJob.cancel

*method*

```python
def cancel(verbose: bool = True) -> None
```

Cancel this specific job with ``scancel``.

Parameters
----------
verbose : bool
    Print a confirmation message. Defaults to True.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L471-L479)

### slurm_script_generator.squeue.SQueueJob.final_state

*method*

```python
def final_state() -> Optional[str]
```

Return this job's accounting state via ``sacct``.

See :func:`job_state`. Returns None when the state cannot be
determined; that is not evidence of failure.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L463-L469)

### slurm_script_generator.squeue.SQueueJob.wait_until_done

*method*

```python
def wait_until_done(poll_interval: float = 30.0, timeout: Optional[float] = None, verbose: bool = True, check: bool = False) -> Optional[str]
```

Block until this specific job leaves the active queue.

Parameters
----------
poll_interval : float
    Seconds between queue polls. Defaults to 30.
timeout : float, optional
    Maximum seconds to wait before raising ``TimeoutError``.
verbose : bool
    Print progress messages. Defaults to True.
check : bool
    Raise ``RuntimeError`` if the job ends in a failure state.
    Defaults to False.

Returns
-------
str or None
    The job's final accounting state, or None if undetermined.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L428-L461)

## slurm_script_generator.squeue.current_user

*function*

```python
def current_user() -> str
```

Return the current OS username (as ``whoami``/``$USER`` would report it).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L525-L529)

## slurm_script_generator.squeue.job_state

*function*

```python
def job_state(job_id: Union[int, str], timeout: float = 30.0) -> Optional[str]
```

Return the state of a job from SLURM accounting (``sacct``).

``squeue`` only says whether a job is still in the queue, not how it ended,
so this is what distinguishes a crashed run from one that simply wrote no
output. States are normalized, e.g. ``'CANCELLED by 1234'`` -> ``'CANCELLED'``.

Parameters
----------
job_id : int or str
    The job ID to look up.
timeout : float
    Seconds to wait for ``sacct`` before giving up. Defaults to 30.

Returns
-------
str or None
    The job state (``'COMPLETED'``, ``'FAILED'``, ``'RUNNING'``, ...), or
    None when it cannot be determined — no accounting configured, ``sacct``
    missing or unresponsive, or the job not yet in the accounting database.
    A None result is *not* evidence of failure and callers should not
    report one.

See Also
--------
job_states : Batch version, one ``sacct`` call for many jobs.

Examples
--------
>>> job_state(12345)
'COMPLETED'

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L218-L253)

## slurm_script_generator.squeue.job_states

*function*

```python
def job_states(job_ids: Union[int, str, List[Union[int, str]]], timeout: float = 30.0) -> Dict[int, Optional[str]]
```

Return the states of several jobs from SLURM accounting (``sacct``).

Uses a single ``sacct`` call for the whole batch, so waiting on many jobs
costs one subprocess rather than one per job. States are normalized,
e.g. ``'CANCELLED by 1234'`` -> ``'CANCELLED'``.

Parameters
----------
job_ids : int, str, or list of int/str
    The job IDs to look up.
timeout : float
    Seconds to wait for ``sacct`` before giving up. Defaults to 30.

Returns
-------
dict of int -> (str or None)
    One entry per requested job ID, in the order given. The value is None
    when the state cannot be determined — no accounting configured,
    ``sacct`` missing or unresponsive, or the job not yet in the accounting
    database. A None value is *not* evidence of failure and callers should
    not report one.

Examples
--------
>>> job_states([12345, 12346])
{12345: 'COMPLETED', 12346: 'FAILED'}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L145-L215)

## slurm_script_generator.squeue.main

*function*

```python
def main() -> None
```

Entry point for the ``slurm-queue`` command-line tool.

Prints the individual-jobs list by default; pass ``--summary`` for the
per-user summary table instead.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1866-L1995)

## slurm_script_generator.squeue.main_history

*function*

```python
def main_history() -> None
```

Entry point for the ``slurm-history`` command-line tool.

Shows job submission history from accounting records (``sacct``).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L2058-L2129)

## slurm_script_generator.squeue.main_stats

*function*

```python
def main_stats() -> None
```

Entry point for the ``slurm-stats`` command-line tool.

Prints partition and state breakdown statistics for the SLURM queue.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L1998-L2055)

## slurm_script_generator.squeue.main_wait

*function*

```python
def main_wait() -> None
```

Entry point for the ``slurm-wait`` command-line tool.

Blocks until matching jobs leave the active queue.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L2132-L2213)

## slurm_script_generator.squeue.task_states

*function*

```python
def task_states(job_ids: Union[int, str, List[Union[int, str]]], timeout: float = 30.0) -> Dict[int, Dict[int, str]]
```

Return the states of the tasks of job arrays.

:func:`job_states` folds the tasks of an array into one state per job;
this keeps them apart, which is what tells the one failed task of an array
from the ninety-nine that finished. The states come from SLURM accounting
(one ``sacct`` call) and, for the tasks still in the queue, from one
``squeue`` call, which is authoritative for those: accounting can lag
behind the queue, and on a system without accounting the queue is all
there is.

Parameters
----------
job_ids : int, str, or list of int/str
    The IDs of the array jobs to look up.
timeout : float
    Seconds to wait for ``sacct`` and for ``squeue``. Defaults to 30.

Returns
-------
dict of int -> dict of int -> str
    For each requested job, the state of each task that is known, by task
    ID: ``'PENDING'``, ``'RUNNING'``, ``'COMPLETED'``, ``'FAILED'``,
    ``'TIMEOUT'``, ... A task that is missing is one whose state cannot be
    determined (it has left the queue and there is no accounting, or
    neither command is available); this is *not* evidence of failure.

See Also
--------
job_states : One state per job, for jobs that are not arrays.

Examples
--------
>>> task_states(12345)
{12345: {1: 'COMPLETED', 2: 'FAILED', 3: 'RUNNING', 4: 'PENDING'}}

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/squeue.py#L304-L376)
