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
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
For HTTP client transport: pip install pulq[http] — see docs/transports.md.
Quick start
PullQueue and Worker use sensible defaults so you can schedule tasks and run a worker with almost no configuration:
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) # default: high / medium / low with 3:2:1 weights, quantum 1
await queue.schedule(Task(priority="high", handler_name="default", payload={"job": "a"}))
await queue.schedule(Task(priority="low", handler_name="default", payload={"job": "b"}))
transport = LocalTransport(queue)
worker = Worker(transport, "worker-1", handle) # default short backoff when idle
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())
Customizing with Pydantic config
For different priorities, weights, quantum, or worker lifecycle hooks on the handler registry, pass validated config objects:
from pulq import DeficitSchedulerConfig, HandlerRegistry, PullQueueConfig, WorkerConfig
queue = PullQueue(
repo,
config=PullQueueConfig(
scheduler=DeficitSchedulerConfig(
priority_order=("critical", "high", "low"),
weights={"critical": 5, "high": 3, "low": 1},
quantum=2,
),
),
)
registry = HandlerRegistry(default=handle, startup=my_startup, shutdown=my_shutdown)
worker = Worker(
transport,
"worker-1",
registry,
config=WorkerConfig(no_work_delay_seconds=0.05),
)
More on HTTP vs local and repositories: docs/transports.md.
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
Releases (PyPI + Read the Docs): after bumping the version in pyproject.toml and updating CHANGELOG.md, merge to main — see docs/releasing.md for trusted publishing setup on PyPI and manual options.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pulq-0.2.1.tar.gz.
File metadata
- Download URL: pulq-0.2.1.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6909507d3ac8fe9b530b719e0a3f8d023a40dc0feb0e63774da5ae78b012f358
|
|
| MD5 |
441f54e69c92649faa4878dbe5bd5e63
|
|
| BLAKE2b-256 |
d57ade9c0d41c311e4d341f55bada586c66ba45ae71af5e4bacad29fb08011de
|
Provenance
The following attestation bundles were made for pulq-0.2.1.tar.gz:
Publisher:
release.yml on vadim-schultz/pulq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pulq-0.2.1.tar.gz -
Subject digest:
6909507d3ac8fe9b530b719e0a3f8d023a40dc0feb0e63774da5ae78b012f358 - Sigstore transparency entry: 1308103169
- Sigstore integration time:
-
Permalink:
vadim-schultz/pulq@bb25933772645495d6a8361e60b85ff777429847 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vadim-schultz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bb25933772645495d6a8361e60b85ff777429847 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pulq-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pulq-0.2.1-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49dd8b7d70aa6611e7fed1d46cefe0794fbc88e4d1d1347249f826b0fa52c992
|
|
| MD5 |
c2d33f7ed7bf3f04fa7a85d785c2c13b
|
|
| BLAKE2b-256 |
1adc07149d954f6e03a5b20abe6e18ddf1ad2e1ff3795351ca0973ddbb17c480
|
Provenance
The following attestation bundles were made for pulq-0.2.1-py3-none-any.whl:
Publisher:
release.yml on vadim-schultz/pulq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pulq-0.2.1-py3-none-any.whl -
Subject digest:
49dd8b7d70aa6611e7fed1d46cefe0794fbc88e4d1d1347249f826b0fa52c992 - Sigstore transparency entry: 1308103308
- Sigstore integration time:
-
Permalink:
vadim-schultz/pulq@bb25933772645495d6a8361e60b85ff777429847 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vadim-schultz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bb25933772645495d6a8361e60b85ff777429847 -
Trigger Event:
push
-
Statement type: