mptrolley
a simple python module to solve problem in a multiprocessing way.
background
there are many jobs which are processed in batches. for example, in many computing tasks, you may need to run a same algorithm on many groups of different input data, and the "subproblems" are often irrelevant with each other. in this case, multiprocessing is a very simple and understandable way to accelerate. so we designed a very simple python module called mptrolley under the principle of KISS (Keep It Simple and Stupid).
terminology
problem and questions
in this passage, we define that a batched job is called a problem. in a single problem, there are may questions, and each question has a continuous numbering (begins from zero). we assume that you have already write a python function to solve a single question:
def question_function(question_index, common_context):
...
and we assume that you can solve your problem without any parallel in the following way:
common = ...
for i in range(question_count): # the questions should be numbered from 0 to (question_count-1)
question_function(i, common)
in this case, mptrolley provides you a simple way to solve the problem faster with multiprocessing:
import mptrolley
common = ...
process_count = ... # an interger to control the number of processes
mptrolley.solve_problem_with_multiprocessing(question_function, common, question_count, process_count)
the question list will be devided into process_count lists according to question_index % process_count. for some question qx and some process px, px will be used to solve qx if and only if qx.question_index % process_count == px.process_index.
install from github release
- go https://github.com/GGN-2015/mptrolley/releases and download a .whl file.
- use pip install
mptrolley-<version>-py3-none-any.whlto install the package into your local environment.
install from pypi
pip install mptrolley
usage
import mptrolley
# define your own question function, it **MUST** have two parameters
# question_index will be given a continuous integer index.
# and common_context is the common information you may need during every question's solving procedure.
# (there are many cases where we just don't need it.)
def question_function(question_index, common_context) -> None:
...
common = ... # common information
process_count = ... # an interger to control the number of processes
mptrolley.solve_problem_with_multiprocessing(question_function, common, question_count, process_count)
Metadata
Release files for mptrolley 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mptrolley-0.0.4.tar.gz | 4.8 kB | Without provenance | Details for mptrolley-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mptrolley-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for mptrolley-0.0.4-py3-none-any.whl |
Total release size: 10.8 kB
Release files / mptrolley-0.0.4.tar.gz
| Download URL | mptrolley-0.0.4.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c15616562efda86b1820c585c8bcc499b223bba763f1126dee09ed4e89765e13
|
|
BLAKE2b-256 checksum How to use checksums |
59fd78825941ebc3246c918aaae5ad0356593bfca6d9bd36b146a86ec01110cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / mptrolley-0.0.4-py3-none-any.whl
| Download URL | mptrolley-0.0.4-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
656f08564e996c9182aacae59a12250bbe08d02a1e7ccfcaa2dd423c47895a90
|
|
BLAKE2b-256 checksum How to use checksums |
e6a6f4fc5b5194131cc910f09c5b1aa507f542edd99b163cd8dd736f7a168e3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for mptrolley 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.