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.2.tar.gz (140.3 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.2-py3-none-any.whl (141.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_alaska-0.1.2.tar.gz
  • Upload date:
  • Size: 140.3 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.2.tar.gz
Algorithm Hash digest
SHA256 7cbd6ef08ab286f1ae2f851ab3d0515cbcd12af535fa8471f667d9f3bac2d902
MD5 cd095c66bde1c2ed564009e07ab20dc1
BLAKE2b-256 007c65b5111563e97d3f306905f05d4a5d0cb6d0ba70e1aa597e7d472a302457

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_alaska-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 141.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca49b183021567f2f73a2413d6fd954c25d86e23ce30562463ed16b232c55672
MD5 ac727939e1685bb3eb7af71f55739997
BLAKE2b-256 a1cbd42bdebd2167ddceb82263c01a6da187f51013ed1abc655a076d5ceb5b8c

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