Skip to main content

ALASKA - Multiprocess Task Management Framework for Python

Project description

ALASKA

Advanced Lightweight Asynchronous Service Kernel for Applications

PyPI version Python License: MIT

A Python framework for building multiprocess task management systems with RMI (Remote Method Invocation), shared memory, and real-time monitoring.

Features

  • Multiprocess Task Management: Run tasks as separate processes or threads
  • RMI (Remote Method Invocation): Call methods across processes seamlessly
  • Shared Memory (SmBlock): Zero-copy image/data sharing between processes
  • Signal/Broker Pattern: Pub/sub messaging between tasks
  • Web Monitoring Dashboard: Real-time HTTP-based monitoring UI
  • Performance Metrics: IPC/FUNC timing statistics with sliding window
  • Auto-restart: Automatic task recovery on failure
  • JSON Configuration: Flexible configuration with injection support

Installation

# Basic installation
pip install py-alaska

# With monitoring support (psutil)
pip install py-alaska[monitor]

# With camera/GUI support (PySide6)
pip install py-alaska[camera]

# Full installation
pip install py-alaska[all]

Quick Start

1. Define a Task

from py_alaska import TaskClass

@TaskClass(name="my_task", mode="process", restart=True)
class MyTask:
    def __init__(self):
        self.task = None  # Injected by framework
        self.counter = 0

    def increment(self, value: int) -> int:
        """RMI method: can be called from other tasks"""
        self.counter += value
        return self.counter

    def get_count(self) -> int:
        """RMI method: query current count"""
        return self.counter

    def task_loop(self):
        """Main loop: runs continuously"""
        while not self.task.should_stop():
            # Do work here
            pass

2. Create Configuration (config.json)

{
    "app_info": {
        "name": "MyApp",
        "version": "1.0.0",
        "id": "myapp_001"
    },
    "task_config": {
        "_monitor": {
            "port": 7000,
            "exit_hook": true
        },
        "worker/my_task": {
            "counter": 0
        }
    }
}

3. Run the Application

from py_alaska import TaskManager, gconfig
import my_task  # Import to register TaskClass

def main():
    gconfig.load("config.json")

    manager = TaskManager(gconfig)
    manager.start_all()

    # Access via RMI
    worker = manager.get_client("worker")
    result = worker.increment(10)
    print(f"Counter: {result}")

    # Web monitor at http://localhost:7000
    import time
    time.sleep(3600)

    manager.stop_all()

if __name__ == "__main__":
    main()

Architecture

┌─────────────────────────────────────────────────────────────┐
│                      TaskManager                            │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐         │
│  │   Task A    │  │   Task B    │  │   Task C    │         │
│  │  (Process)  │  │  (Process)  │  │  (Thread)   │         │
│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘         │
│         │                │                │                 │
│         └────────────────┼────────────────┘                 │
│                          │                                  │
│                    ┌─────┴─────┐                            │
│                    │  RMI Bus  │                            │
│                    │  (Queue)  │                            │
│                    └─────┬─────┘                            │
│                          │                                  │
│                    ┌─────┴─────┐                            │
│                    │  SmBlock  │                            │
│                    │ (Shared)  │                            │
│                    └───────────┘                            │
├─────────────────────────────────────────────────────────────┤
│                    TaskMonitor                              │
│                  HTTP :7000                                 │
└─────────────────────────────────────────────────────────────┘

Core Components

Component Description
TaskManager Main orchestrator for all tasks
TaskClass Decorator to define a task
RmiClient Client for calling remote methods
SmBlock Shared memory block pool for zero-copy data sharing
Signal/SignalBroker Pub/sub messaging system
TaskMonitor HTTP-based web monitoring dashboard
GConfig Global configuration management

API Reference

TaskClass Decorator

@TaskClass(
    name="task_name",      # Unique task identifier
    mode="process",        # "process" or "thread"
    restart=True,          # Auto-restart on failure
    restart_delay=3.0,     # Delay before restart (seconds)
)

RMI Methods

Any public method in a TaskClass becomes an RMI method:

# In Task A
def calculate(self, x: int, y: int) -> int:
    return x + y

# From Task B or main process
client = manager.get_client("task_a")
result = client.calculate(10, 20)  # Returns 30

SmBlock (Shared Memory)

# Configuration
"_smblock": {
    "image_pool": {"shape": [1024, 1024, 3], "maxsize": 100}
}

# In task
index = self.smblock.malloc()      # Allocate block
image = self.smblock.get(index)    # Get numpy array
image[:] = frame                   # Write data
self.smblock.mfree(index)          # Release block

Monitoring

Access the web dashboard at http://localhost:7000 (configurable port).

Features:

  • Real-time task status (alive/stopped)
  • RMI call statistics (count, timing)
  • CPU/Memory usage per task
  • SmBlock pool utilization
  • Configuration editor
  • Performance metrics (IPC/FUNC time)

Requirements

  • Python >= 3.8
  • numpy >= 1.20.0
  • psutil >= 5.8.0 (optional, for monitoring)
  • PySide6 >= 6.0.0 (optional, for camera/GUI)

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

py_alaska-0.1.0.tar.gz (89.0 kB view details)

Uploaded Source

Built Distribution

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

py_alaska-0.1.0-py3-none-any.whl (87.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_alaska-0.1.0.tar.gz
  • Upload date:
  • Size: 89.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for py_alaska-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ff88040e804b29e7085d138c8839f42c103491a7b5e3f663f4328b3546fdba99
MD5 ff39f10b2f483d3c29a7d28bad627ea2
BLAKE2b-256 742037c6ab359e0ce0cc5e18896618a63448f1a4f4762a03dba1326c51af2556

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_alaska-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 87.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for py_alaska-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89656a2191a0a5384ae0ce2191716febaa8cc4732af03ae56d36f051ad1873b8
MD5 16d46554de505724aa56814dc594c269
BLAKE2b-256 241e90f2379919ba0d165d9e18f0cbc840b5a8e0fd6bded8de0efcfc8fc824bd

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