Skip to main content

Full-featured job queue system with multiprocessing support for Linux

Project description

Queue Manager

A Python-based job queue system with per-job processes and signal variables.

Features

  • Per-Job Processes: Each job runs in its own OS process for isolation
  • Signal Variables: Jobs communicate via shared state protected by mutexes
  • Registry Persistence: Job states and results are persisted to a registry
  • Process Control: Start, stop, and delete jobs with graceful termination
  • Progress Tracking: Real-time progress updates and status monitoring
  • Error Handling: Comprehensive error handling and recovery mechanisms

Multiprocessing start method

queuemgr creates every job/manager process from its own local multiprocessing context (see queuemgr/mp_context.py) instead of relying on the process-wide default. That context defaults to spawn, which does not fork the calling process and therefore does not duplicate live threads, open sockets, or an in-flight asyncio event loop (e.g. a running asyncio/hypercorn server) into the child.

queuemgr never calls multiprocessing.set_start_method, so it does not read or mutate the global default start method used by your application or other libraries. If you need a different method (for example because your deployment environment cannot use "spawn"), set the QUEUEMGR_MP_START_METHOD environment variable to "spawn", "forkserver", or "fork" before queuemgr creates its first process.

export QUEUEMGR_MP_START_METHOD=forkserver

Installation

pip install queuemgr

Quick Start

from queuemgr.queue.job_queue import JobQueue
from queuemgr.core.registry import JsonlRegistry
from queuemgr.jobs.base import QueueJobBase
from queuemgr.core.types import JobStatus
from queuemgr.core.ipc import update_job_state

class MyJob(QueueJobBase):
    def execute(self):
        # Your job logic here
        for i in range(100):
            update_job_state(
                self._shared_state,
                progress=i,
                description=f"Processing item {i}"
            )
    
    def on_start(self):
        update_job_state(self._shared_state, description="Job started")
    
    def on_stop(self):
        update_job_state(self._shared_state, description="Job stopped")
    
    def on_end(self):
        update_job_state(self._shared_state, description="Job completed")
    
    def on_error(self, exc):
        update_job_state(self._shared_state, description=f"Job failed: {exc}")

# Create queue and job
registry = JsonlRegistry("my_registry.jsonl")
queue = JobQueue(registry)
job = MyJob("my-job-1", {"param": "value"})

# Add and start job
queue.add_job(job)
queue.start_job("my-job-1")

# Monitor progress
status = queue.get_job_status("my-job-1")
print(f"Status: {status.status}, Progress: {status.progress}%")

Examples

See the examples/ directory for complete examples:

  • simple_job.py - Basic job creation and execution
  • error_handling_job.py - Error handling and recovery
  • progress_job.py - Long-running job with progress updates
  • registry_example.py - Registry functionality and job history

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=queuemgr

# Format code
black queuemgr tests

# Lint code
flake8 queuemgr tests

# Type check
mypy queuemgr

License

MIT License - see LICENSE file for details.

Author

Vasiliy Zdanovskiy - vasilyvz@gmail.com

vvz-queuemgr

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

queuemgr-1.0.20.tar.gz (140.7 kB view details)

Uploaded Source

Built Distribution

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

queuemgr-1.0.20-py3-none-any.whl (168.3 kB view details)

Uploaded Python 3

File details

Details for the file queuemgr-1.0.20.tar.gz.

File metadata

  • Download URL: queuemgr-1.0.20.tar.gz
  • Upload date:
  • Size: 140.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for queuemgr-1.0.20.tar.gz
Algorithm Hash digest
SHA256 4bbb023da57bba38bdfb13f2649bcec2bf9477f52ce419d4156e9e75d5c8b523
MD5 db2da5d930a4d5a2f7539350790920f3
BLAKE2b-256 75f856dc95c2ebdd6e84c592656f12e575a36eda2a6f329a95ef3db21015085c

See more details on using hashes here.

File details

Details for the file queuemgr-1.0.20-py3-none-any.whl.

File metadata

  • Download URL: queuemgr-1.0.20-py3-none-any.whl
  • Upload date:
  • Size: 168.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for queuemgr-1.0.20-py3-none-any.whl
Algorithm Hash digest
SHA256 36a790c490bb23c14e2b171321eeeeca158117d3c1c95a01d07257997cc10bad
MD5 ae2784c4643eab8db6195228f6235cb9
BLAKE2b-256 e5081891c71c903bd858d30a63d1102a63d7fc561ad94c61d0bd453d8beb8a66

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