Skip to main content

A Python library integrates APIs of multiprocessing, threading, gevent and asyncio.

Project description

MultiRunnable

Supported Versions Release PyPI version License Codacy Badge Documentation Status

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

A Python library integrates the APIs of 3 strategies (Parallel, Concurrent, Coroutine) and 4 libraries (multiprocessing, threading, gevent, asyncio) to help developers build parallelism humanly.

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


Overview

Package 'multirunnable' is a library 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.17.0a1.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

MultiRunnable-0.17.0a1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file MultiRunnable-0.17.0a1.tar.gz.

File metadata

  • Download URL: MultiRunnable-0.17.0a1.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for MultiRunnable-0.17.0a1.tar.gz
Algorithm Hash digest
SHA256 4855e3207eae27189b4d5cba578a4ad3d0cbf6d16067aeb702b94484672de9e1
MD5 68b2bb22ec4dc3a20f4a271390a90923
BLAKE2b-256 cf03020439d24854187c9dbc8f48abb1c51052d4e3c8802b15cf40979b04d44d

See more details on using hashes here.

File details

Details for the file MultiRunnable-0.17.0a1-py3-none-any.whl.

File metadata

  • Download URL: MultiRunnable-0.17.0a1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for MultiRunnable-0.17.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ff3e358ea6efc28ba9e40d656c81b3e7a6f39f7ba3f9a1041ebad9e99de4d85
MD5 e67c40a843fff4e28e3dab43e6185294
BLAKE2b-256 1603ff4f1567be1c8fdbcb31db6f3e6c18ccbc3a9953ad618d6e6dc377c36540

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