Skip to main content

Flask-Multiprocess-Controller is an extension for Flask that provides an easy-to-implement controller for multiprocessing tasking. It provides default functions such as task-queueing, health-check, status-check, manual-stop and process-safe logger.

A common usage scenario is one has some tasks which are computational expensive and require multiple instances running concurrently. This controller provides a separate layer of controller by creating controlling thread for each instance. This can greatly improve level-of-control for computational expensive tasks.

Features

Flask-Multiprocess-Controller provides the MetaMPController() class which provides default controlling method to control the execute() method in the linked, child of MetaMPTask() class. Default controlling methods are as follows: - GET: retrieve the current status of certain task in sub-process - POST: put an execution request to the queue waiting to be executed when there is a new slot for a new sub-process - DELETE: sending the stop signal to certain task in sub-process gently

All Flask supported HTTP methods are supported(with necessary overrides)

One can also use MetaMPResource() class to adopt Flask-RESTful style APIs.

Example: Build a minimal Controller-Task structure

In the following example, we will use the built-in TemplateMPController, and TemplateMPResource to build the structure of controller-task framework. One may need to override some methods in MetaMPController for more functionality.

import logging
from flask import Flask
from flask_restful import Api
from flask_multiprocess_controller import TemplateFactory, MetaMPTask

class SampleTask(MetaMPTask):

    def execute(self) -> None:
        task_logger = logging.getLogger(str(os.getpid()))
        counter = 0
        while counter < 100:
            counter += 1
            task_logger.debug("doing some simple task, progress {}%.".format(counter))
            time.sleep(0.5)
            self.upload_status(counter)
            self.checkpoint()

sample_api = Api()
sample_controller = TemplateFactory.MPController(name='Sample')(target_task=SampleTask, max_num_process=2)
sample_api.add_resource(TemplateFactory.MPResource(), '/sample', resource_class_args=(sample_controller,))

app = Flask('Sample')
sample_api.init_app(app)
app.run()

Installation

The easiest way to install it is using pip from PyPI

pip install flask-multiprocess-controller

License

See the LICENSE file for license rights and limitations (BSD-3-Clause).

Metadata

Release files for Flask-Multiprocess-Controller 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Multiprocess-Controller 0.1.1
File Size Uploaded
Flask-Multiprocess-Controller-0.1.1.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Multiprocess-Controller 0.1.1
File Interpreter ABI Platform
Flask_Multiprocess_Controller-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 24.5 kB

Release files / Flask-Multiprocess-Controller-0.1.1.tar.gz

Download URL Flask-Multiprocess-Controller-0.1.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
79521f76e7037440fa77961ca251b58909c48b14926a2442774ee63448a2fa20
BLAKE2b-256 checksum
How to use checksums
0941825d8b0284f93445d86bb3ab89b17349d6a162c0bf06280b37bd154c1547
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.11

Release files / Flask_Multiprocess_Controller-0.1.1-py3-none-any.whl

Download URL Flask_Multiprocess_Controller-0.1.1-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
104ae4fe745a74ba3d4e932eceb9753270a8290b6d7dd1ee3ef854b05d5cb98f
BLAKE2b-256 checksum
How to use checksums
cf0428215ca9008766efedce137a428159f3879f347534c8b00d3fb6a2841d05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.11

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1

2 release files

0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page