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) via 4 libraries (multiprocessing, threading, gevent, asyncio) to help developers build parallelism humanly.

Overview | Quickly Start | Syntactic Sugar in MultiRunnable | Documentation | 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 builds 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 in MultiRunnable

It could use some features via Python decorator in MultiRunnable.

Following code is a demonstration about usage with 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.

Documentation

The documentation contains more details, and examples.

  • Quickly Start to develop parallelism with MultiRunnable
  • Detail MultiRunnable usage information of functions, classes and methods in API References.
  • Be curious about how to join and develop MultiRunnable? Development Documentation could be a good guide for you.

Download

MultiRunnable still a young open source which keep growing. Here's its download state:

Downloads Downloads

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.0.tar.gz (117.2 kB view hashes)

Uploaded Source

Built Distribution

MultiRunnable-0.17.0-py3-none-any.whl (160.9 kB view hashes)

Uploaded Python 3

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