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 rmi_class

@rmi_class(name="my_task", mode="process", restart=True)
class MyTask:
    def __init__(self):
        self.runtime = 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.runtime.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 rmi_class

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
rmi_class 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

rmi_class Decorator

@rmi_class(
    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 rmi_class 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.14.tar.gz (995.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.14-py3-none-any.whl (998.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_alaska-0.1.14.tar.gz
  • Upload date:
  • Size: 995.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.14.tar.gz
Algorithm Hash digest
SHA256 41dcf25285b590b5b7f1f43754493d9f8e896fcb490e654f26a4a98117106dab
MD5 9262b9e105424f36564ad53868eec4e7
BLAKE2b-256 f75171839b450edf594b3147baf09e2dbf04c8467036dcf58729e9475cd6043c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_alaska-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 998.6 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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 9649999a52dc975b0812dcafe82c2aae8afd817519549f63f94b6818e359df7d
MD5 a9b9c906d386bb10bfbf06835a65d554
BLAKE2b-256 269da9a53d9116dbf68b7db71cfe350be40f218417cb5037aeeb9b536f203d91

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