A Python library integrates APIs of multiprocessing, threading, gevent and asyncio.
Project description
MultiRunnable
OS | Building Status | Coverage Status |
---|---|---|
Linux / MacOS | ||
Windows |
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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file MultiRunnable-0.17.0.tar.gz
.
File metadata
- Download URL: MultiRunnable-0.17.0.tar.gz
- Upload date:
- Size: 117.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ec165d9d70ac2f3ec19e4ddeda435230cefc5f4162ec5d4b05e4e0728e56b4a |
|
MD5 | 282f8384dc882baedebc197dbc5e66bc |
|
BLAKE2b-256 | f3dca7764ad0e85e2c0c09e7ae45a6ea7ac7ab0e23b4365d053fd1edf91a6690 |
File details
Details for the file MultiRunnable-0.17.0-py3-none-any.whl
.
File metadata
- Download URL: MultiRunnable-0.17.0-py3-none-any.whl
- Upload date:
- Size: 160.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd265f87d7298e9b76a462728aa0c9ab35958e05bd3a74b4f794684e9bb31732 |
|
MD5 | 61e7851355c33375179776a4031df481 |
|
BLAKE2b-256 | e002deb3ef9aae3f3d690efab5ef8cf464b0dbae82f58ad31822dbb35484a3e5 |