Skip to main content

A Python framework integrates running multiple tasks simultaneously with different strategy.

Project description

multirunnable

Supported Versions Release PyPI version License Documentation Status

OS Building Status Coverage Status
Linux Build Status codecov
Linux CircleCI codecov
Linux multirunnable testing codecov
Windows Build status Coverage Status

A Python framework integrates how to build parallelism with different running strategy.

Overview | Quickly Start | Syntactic Sugar | Resource | Code Example


Overview

Package 'multirunnable' is a framework which could easily build a parallelism with different running strategy by mode option. Currently, it has 4 options could use: Parallel, Concurrent, GreenThread and Asynchronous.

Here's an example which implements parallelism as concurrent with multirunnable:

from multirunnable import SimpleExecutor, RunningMode
import time

Workers_Number = 5

def function(index):
    print(f"This is function with index {index}")
    time.sleep(3)


if __name__ == '__main__':
  
    executor = SimpleExecutor(mode=RunningMode.Concurrent, executors=Workers_Number)
    executor.run(function=function, args={"index": f"test_arg"})

How about parallel? Only one thing you need to do: change the mode.

... # Any code is the same

executor = SimpleExecutor(mode=RunningMode.Parallel, executors=Workers_Number)

... # Any code is the same

Program would turn to run as parallel and work finely.
Want change to use other way to run? Change the Running Mode, that's all.

⚠️ Parallel, Concurrent and GreenThread are in common but Asynchronous isn't.
From above all, we could change the mode to run the code as the running strategy we configure. However, it only accepts 'awaitable' function to run as asynchronous in Python. In the other word, you must remember add keyword 'async' before function which is the target to run with multirunnable.

Quickly Start

Install this package by pip:

pip install multirunnable

Write a simple code to run it.

>>> from multirunnable import SimpleExecutor, RunningMode
>>> executor = SimpleExecutor(mode=RunningMode.Parallel, executors=3)
>>> def function(index):
...     print(f"This is function with index {index}")
... 
>>> executor.run(function=function, args={"index": f"test_param"})
This is function with index test_param
This is function with index test_param
This is function with index test_param
>>> 

Syntactic Sugar

It could implement some features via Python decorator in MultiRunnable.

For example, Lock via decorator RunWith (it's AsyncRunWith with Asynchronous):

from multirunnable.api import RunWith
import time

@RunWith.Lock
def lock_function():
    print("Running process in lock and will sleep 2 seconds.")
    time.sleep(2)

✨👀 All below features support decorator:
Lock, RLock, Semaphore, Bounded Semaphore.

Resource

The documentation contains more details, and examples.

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

multirunnable-0.16.0.tar.gz (132.6 kB view details)

Uploaded Source

Built Distribution

multirunnable-0.16.0-py3-none-any.whl (210.7 kB view details)

Uploaded Python 3

File details

Details for the file multirunnable-0.16.0.tar.gz.

File metadata

  • Download URL: multirunnable-0.16.0.tar.gz
  • Upload date:
  • Size: 132.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for multirunnable-0.16.0.tar.gz
Algorithm Hash digest
SHA256 0df7d8a0a619d31dade77dbddfbff5462698f8eeff34505ad41f0abc958ce92e
MD5 c634ca2d7465a27b350f79635462e33f
BLAKE2b-256 44c383d1c1ec4738bdef6df83e6c69d52c484ad2c1b0ae4505e351f4181c245f

See more details on using hashes here.

File details

Details for the file multirunnable-0.16.0-py3-none-any.whl.

File metadata

  • Download URL: multirunnable-0.16.0-py3-none-any.whl
  • Upload date:
  • Size: 210.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for multirunnable-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b32355908909d5474e34b3f4ae6f3d8866390b27a3f2aa213c651bac785a82d9
MD5 6cc4b4941deaeb401368d0c125c0c972
BLAKE2b-256 8cb71091b7dd1c9a4d6d1b2dcffa8d842f7ecb322d4c09f00fd74779a33ffd67

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page