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.2.0.tar.gz (35.2 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.2.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stagegate-0.2.0.tar.gz
  • Upload date:
  • Size: 35.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 f4331a6589bdfcef88ce1e19c578195fd1637a6330494e30454d3a1d6f6cc16f
MD5 71dcddd8b1511f2ec5882ae9e0f360bb
BLAKE2b-256 eba1df5424c8eb48a2b073255006089355bc12f5ff4162f7f215156fff15c874

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stagegate-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae9a04058c764ee03a9e18a04cd6e4dfdd744c92eaef78cb7167a22963f13c2b
MD5 fda8b8c3738e3746fa36549e6caccca8
BLAKE2b-256 b320b7d7a7c44c194debf6a92563e0c238c5f129bdecb78da8b1c0a66ec1aa63

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