Skip to main content

A small, explicit scheduler for forward-only pipelines with stage-aware task priority.

Project description

stagegate

stagegate is a small, explicit, single-process Python library for running many forward-only pipelines with:

  • FIFO pipeline scheduling
  • stage-aware task priority
  • strict head-of-line blocking
  • abstract resource quotas

It is aimed at local batch workloads that have grown beyond a plain thread pool but do not justify a full workflow engine.

Why Stagegate

stagegate is built for workloads where:

  • many similar pipelines run on one machine
  • tasks have heterogeneous CPU / memory / other resource needs
  • later-stage work should be preferred over endlessly producing more upstream intermediates
  • tasks that spend meaningful time in NumPy, SciPy, Pandas, other C-extension code, or external CLI tools

The scheduler stays intentionally small:

  • one Python process
  • multiple threads
  • no DAG engine
  • no persistence layer
  • no distributed runtime

Install

pip install stagegate

Quick Example

import stagegate


class ExamplePipeline(stagegate.Pipeline):
    def run(self) -> int:
        a = self.task(step_a, resources={"cpu": 1}).run()
        b = self.task(step_b, resources={"cpu": 1}).run()

        self.wait([a, b], return_when=stagegate.ALL_COMPLETED)
        result_a = a.result()
        result_b = b.result()

        self.stage_forward()

        c = self.task(
            combine,
            resources={"cpu": 4, "mem": 16},
            args=(result_a, result_b),
        ).run()
        return c.result()


with stagegate.Scheduler(
    resources={"cpu": 8, "mem": 32},
    pipeline_parallelism=2,
    task_parallelism=4,
) as scheduler:
    handle = scheduler.run_pipeline(ExamplePipeline())
    print(handle.result())

Cooperative Terminate

For long-running tasks, stagegate supports cooperative terminate:

  • TaskHandle.request_terminate()
  • stagegate.terminate_requested()
  • stagegate.run_subprocess(...)

The scheduler itself does not forcibly stop arbitrary running Python code or running pipelines. Cooperative terminate is opt-in.

stagegate.run_subprocess(...) is currently intended for POSIX platforms such as Linux, macOS, and BSD. stagegate itself may still be usable on Windows if your tasks do not depend on that helper.

Documentation

User's guide, use cases and API reference can be found at http://stagegate.readthedocs.io.

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

stagegate-0.3.0.tar.gz (79.0 kB view details)

Uploaded Source

Built Distribution

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

stagegate-0.3.0-py3-none-any.whl (49.3 kB view details)

Uploaded Python 3

File details

Details for the file stagegate-0.3.0.tar.gz.

File metadata

  • Download URL: stagegate-0.3.0.tar.gz
  • Upload date:
  • Size: 79.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for stagegate-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e3b194a9bb222d980a7b5bee157bdf163cb9b187269a8844ac661e0f7712984e
MD5 97da7043f9a5a0dd205bc0e6b5cb2535
BLAKE2b-256 a0409e2101ce229169e094aa02f854fd5ec8ea191ebb6b77b6c2a68d7c7198a4

See more details on using hashes here.

File details

Details for the file stagegate-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: stagegate-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 49.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for stagegate-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ac53eaf287c3fd235a242a03efc08e43568e2ef0ab82f830d232a1be863005a
MD5 7cc2c32e7fe046c6e1433917ad48569b
BLAKE2b-256 fb598521755f8a29e1fed1bfb4d1ece350e00250d723fa71dd9a969adf99b304

See more details on using hashes here.

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