Process Parallelization
Project description
PARPROC
A library for parallelizing scripts, by allowing different script elements to be grouped in processes, and allowing each group to depend on the completion of one or more other groups
Installation and Usage
Installation
pip install parproc
Usage
See examples/success.py for an example. Different jobs can be defined and dependencies between them established, e.g.:
import parproc as pp
@pp.Proc(now=True)
def func0(context):
time.sleep(1)
@pp.Proc(now=True)
def func1(context):
time.sleep(3)
@pp.Proc(now=True)
def func2(context, deps=['func0', 'func1']):
time.sleep(2)
The now=True argument kicks off the jobs as soon as they are defined, which is optional. The example then waits for all jobs to finish
pp.wait_for_all()
Argument choices and glob expansion
Protos can define allowed values for arguments via arg_choices. When set, only those values are accepted when creating procs, and you can use glob patterns (*, ?) in filled-out names to create multiple procs at once:
@pp.Proto(name='build::[env]', arg_choices={'env': ['dev', 'prod']})
def build(context: pp.ProcContext, env: str) -> str:
return f'built_{env}'
# Create one proc
pp.create('build::dev')
# Create all matching procs: build::dev and build::prod
names = pp.create('build::*')
pp.start(*names)
pp.wait(*names)
Using * or ? in an argument when the proto has no arg_choices for that argument raises an error.
Contributing
Feel free to send me PRs
Setting up the development environment
- Install uv if you haven't already
- Clone the repository
- Initialize the development environment:
uv sync --dev
This will install all dependencies and development tools.
Running tests
Run all tests using the test script:
./scripts/test.sh
Or run specific test modules:
./scripts/test.sh tests.simple tests.proto
You can also run tests directly with uv:
uv run python -m unittest tests.simple tests.proto tests.errorformat
Running examples
Run any of the example scripts:
uv run python examples/success.py
uv run python examples/error.py
uv run python examples/failed_deps.py
Change Log
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 parproc-0.4.0.tar.gz.
File metadata
- Download URL: parproc-0.4.0.tar.gz
- Upload date:
- Size: 34.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
352c85912d6ca399f4d642168b6596cdd1fc06c9765872a127f54aca5a339755
|
|
| MD5 |
7efe9c3620447c219e21329930f97e8b
|
|
| BLAKE2b-256 |
cbc7e0eb238817ea4d34ffcfbedfc9195dc238a79fe2265a24135d4c7a0ec89d
|
File details
Details for the file parproc-0.4.0-py3-none-any.whl.
File metadata
- Download URL: parproc-0.4.0-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
768e1ce31a7ff9b62b666a557be38449614edc9496b98b246ae3f5d224b80684
|
|
| MD5 |
14341c80733c855d7ef2ea34e29b49bc
|
|
| BLAKE2b-256 |
ce1ccd84a187e68a55249c14597e3bd8c98d3627ca82d104235999d40be0f155
|