Skip to main content

Fair task scheduling with async pull: WDRR-based priority queue for Python

Project description

PULQ

Fair task scheduling with async pull — WDRR-based priority queue for Python

CI Documentation Status PyPI version

PULQ schedules pull-based work across named priority buckets using Weighted Deficit Round Robin (WDRR) so higher-weight classes get proportionally more CPU time without starving lower classes. Management commands (e.g. STOP) are delivered per worker ahead of normal tasks.

Install

pip install pulq

Quick start

import asyncio

from pulq import (
    CommandType,
    InMemoryTaskRepository,
    LocalTransport,
    PullQueue,
    Task,
    Worker,
)

async def handle(task: Task) -> dict:
    return {"ok": True, "echo": task.payload}

async def main() -> None:
    repo = InMemoryTaskRepository()
    queue = PullQueue(
        repo,
        priority_order=("high", "medium", "low"),
        weights={"high": 3, "medium": 2, "low": 1},
        quantum=1,
    )
    await queue.schedule(Task(priority="high", payload={"job": "a"}))
    await queue.schedule(Task(priority="low", payload={"job": "b"}))

    transport = LocalTransport(queue)
    worker = Worker(transport, "worker-1", handle, no_work_delay_seconds=0.01)

    async def stop_later() -> None:
        await asyncio.sleep(0.05)
        queue.send_command("worker-1", CommandType.STOP)

    await asyncio.gather(worker.run(), stop_later())

asyncio.run(main())

Documentation

Full docs: pulq.readthedocs.io

Development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
ruff check src tests
mypy src
pytest

License

MIT — see LICENSE.

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

pulq-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

pulq-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file pulq-0.1.0.tar.gz.

File metadata

  • Download URL: pulq-0.1.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pulq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2c1a038a5cef7bf5259d44f0de6f0765899205d9c65cc16a9f650dc882d49740
MD5 3c9c018509619ca845c96a404b6c347e
BLAKE2b-256 c0a49eba7778b09baa3ca8322e98b67cd7102a782642e9ddef42d6cb5ac261d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulq-0.1.0.tar.gz:

Publisher: publish.yml on vadim-schultz/pulq

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

File details

Details for the file pulq-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pulq-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pulq-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98a203af159cf4afdb4736aceaf9cfd0104abeb13c0772bbc5c02651a0218776
MD5 a8607fabe2f8d803b6f3674442a9e806
BLAKE2b-256 ee33eded75d08f5acf0b3da4626207594f28caa7ffaef68759c7cc2c99410905

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulq-0.1.0-py3-none-any.whl:

Publisher: publish.yml on vadim-schultz/pulq

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