Skip to main content

No project description provided

Project description

Slurm Longrun

Slurm Longrun is a Python package that wraps Slurm’s sbatch command to automatically resubmit jobs that time out, allowing you to run workloads that exceed a single‐job walltime without manual intervention. It supports optional terminal detachment (so your monitor survives after you log out), configurable retry limits, and built-in logging via Loguru.


Installation

Prerequisites

  • Python 3.10+
  • Slurm workload manager (sbatch, sacct, scontrol in your PATH)

Install from PyPI:

pip install slurm-longrun

Quickstart

Instead of calling sbatch directly, use the sbatch_longrun wrapper:

sbatch_longrun [OPTIONS] [SBATCH_ARGS…]

Everything after -- is passed directly to sbatch.

Example: your job runs longer than 30 minutes, so you give it a 30 min walltime and let Longrun resubmit on timeout:

sbatch_longrun --max-restarts 5 --time=00:30:00 --job-name=my_job -- my_script.sbatch

This will:

  1. Submit my_script.sbatch with a 30 min limit.
  2. When it hits the 30 min walltime (TIMEOUT), automatically resubmit (appending to the same log file).
  3. Repeat up to 5 times or until the job completes successfully.

Command-Line Interface

Usage

sbatch_longrun [OPTIONS] [SBATCH_ARGS…]

Options

  • --use-verbosity [DEFAULT|VERBOSE|SILENT]
     Logging level (DEFAULT = INFO, VERBOSE = DEBUG, SILENT = WARNING).
  • --detached / --no-detached
     Run the monitor loop in background (detached from your terminal).
  • --max-restarts INTEGER
     Maximum number of resubmissions on TIMEOUT. Default: 99.
  • -h, --help
     Show help and exit.

All other flags after -- are forwarded to sbatch.

Examples

  1. Basic, retry up to 3 times, verbose logging:

    slurm-longrun --use-verbosity VERBOSE --max-restarts 3 -- \
      --time=02:00:00 --job-name=deep_train train.sbatch
    
  2. Detach the monitor so it survives logout:

    slurm-longrun --detached -- \
      --time=01:00:00 --job-name=data_proc data_pipeline.sbatch
    # → prints “Monitor running in background PID: ”
    

How It Works

  1. Submit
    Calls sbatch with your arguments; parses the returned job ID.
  2. Monitor
    • Polls sacct + scontrol until the job reaches a terminal state.
    • If TIMEOUT and you haven’t exceeded --max-restarts, it immediately resubmits with --open-mode=append to preserve logs.
  3. Detach (optional)
    If --detached is passed, the process forks twice, detaches from the terminal (setsid), redirects stdio to /dev/null, and continues monitoring in background.

Environment Variables

SLURM_LONGRUN_INITIAL_JOB_ID

  • Set internally to the first submission’s job ID.
  • You can read it in your job script (e.g., to name checkpoints).

Dependencies

  • click
  • loguru

These are installed automatically via pip.


Summary of CLI Options

Option Default Description
--use-verbosity DEFAULT Logging verbosity: DEFAULT (INFO), VERBOSE, SILENT (WARNING)
--detached / --no-detached --no-detached Detach monitoring loop into background process
--max-restarts 99 Max auto-resubmissions on TIMEOUT
-- [SBATCH_ARGS…] All subsequent flags passed directly to sbatch

Enjoy uninterrupted long‐running Slurm jobs! 🐢→🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slurm_longrun-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slurm_longrun-0.1.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file slurm_longrun-0.1.2.tar.gz.

File metadata

  • Download URL: slurm_longrun-0.1.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for slurm_longrun-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2d1ed33f1c2b00aaa156ad64a0259ea819f7e43f19bcc075002c7994420400a7
MD5 968d3a3069cd8a355c4a61a44285589f
BLAKE2b-256 54e614c61622fe3752a8e4427448e78adb7ad1f97592825788d9fa576740f7ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for slurm_longrun-0.1.2.tar.gz:

Publisher: pypi-publish.yml on alexthillen/slurm_longrun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slurm_longrun-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: slurm_longrun-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for slurm_longrun-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c0f3c74e15ad68760db2dc90556b90c01850290ce7fcda13d5af20d270fc0094
MD5 f45479445202f3f5c73d718338f22a09
BLAKE2b-256 72eda6934927a6d9df2393385c5b32e238c0a9673c50135db7b1948d0622a23b

See more details on using hashes here.

Provenance

The following attestation bundles were made for slurm_longrun-0.1.2-py3-none-any.whl:

Publisher: pypi-publish.yml on alexthillen/slurm_longrun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page