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 / MacOS MultiRunnable CI/CD codecov
Windows CircleCI 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.0a2.tar.gz (116.4 kB view details)

Uploaded Source

Built Distribution

MultiRunnable-0.17.0a2-py3-none-any.whl (160.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: MultiRunnable-0.17.0a2.tar.gz
  • Upload date:
  • Size: 116.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for MultiRunnable-0.17.0a2.tar.gz
Algorithm Hash digest
SHA256 28dee058253d2df4d1ed61a4af1ca61175971ce6034ab16735949c3f25763f96
MD5 56ecb95b2042647480a5c6eaef78aa48
BLAKE2b-256 884f1efd993332c16bbe5ea6cc221e814ccf6720b8aca7a8f0aebb6eca240334

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for MultiRunnable-0.17.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 76f1c1bc547f7028647e262912c855753c7b7dec6f5d08d630de93318aa84183
MD5 c76500f1206af2e04041d1abde5b0f68
BLAKE2b-256 bb4c608d8c372792572c85fadbba9d441617e6ce035355521fbf283cb2417449

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