a drop-in and easy-use enhancement for multiprcocessing
Project description
multiprocplus
multiprocessing plus, a drop-in and easy-use enhancement for multiprcocessing
- easy to replace "for loop".
- assign task group with given an estimated cost.
install
# install method 1: from source code
git clone https://github.com/yinglang/multiprocplus
cd multiprocplus
python setup.py install
# install method 2: from pip
pip install multiprocplus
Usage
from multiprocplus import multiprocess_for, MultiprocessRunner
# func passed to new process must be global function or
# member function of global class, and not lambda function
def func(a, b):
return a * b
if __name__ == "__main__":
N = 100
A, B = list(range(N)), list(range(N))
# run in single process
C = [func(a, b) for a, b in zip(A, B)]
print(sum(C))
# => run in multiprocess
# only allow to be called under 'if __name__ == "__main__"' of entry script
C = multiprocess_for(func, [(a, b) for a, b in zip(A, B)], num_process=3)
print(sum(C))
For more usage examples, see doc/usage.md
Notice:
- The definition of function passed to new process must be out of 'if name == "main"' (global function or member function of global class), and can not be lambda function;
- Code/Function that you do not want to run in new process must be written/called under 'if name == "main"' of entry script, or it will run/called in new process.
- Following last note, multiprocess_run must be called in a function called under 'if name == "main"' of entry script. Otherwise, new processes will be generated recursively
For error usage examples, to see doc/normal_issue.md or test/error_usage
Basic && Implementation
Manager & Pool in multiprocessing
If you have known the usage of module multiprocessing in python, you can skip this section. see CSDN
Implementation
If you just want to use multiprocplus in you project and do not interest the implementation, you can skip this section.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multiprocplus-0.2.tar.gz.
File metadata
- Download URL: multiprocplus-0.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
665eb905d8ec40a5d67f3ca15e225b31c2b3afc43518c28d59ab7f05b750295a
|
|
| MD5 |
2ff345ea8858df4fb365c54cae983c32
|
|
| BLAKE2b-256 |
461d541c177ea9a1cd2f3b32a07081ef7f9d2408ade7df46cd881533430bd04a
|
File details
Details for the file multiprocplus-0.2-py3-none-any.whl.
File metadata
- Download URL: multiprocplus-0.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00e7964c6dae1dfe783c8670c10fe06176335261f3e75a8003d9d8c04f83cdaf
|
|
| MD5 |
632947f230e0351e6306c248837f02cd
|
|
| BLAKE2b-256 |
27d33e8aeee81307f6d99f81ac9738ad086c5243d8f1f43658f2e9041dff18c7
|