parallel-iterator
A parallel iterator execution library for Python, providing various executors for concurrent and parallel task processing.
Installation
pip install parallel-iterator
Or install from source:
git clone https://github.com/lh9171338/parallel-iterator.git
cd parallel-iterator
pip install -e .
Quick Start
import time
from parallel_iterator import ProcessExecutor
# Define a task function
def process(a, b, delay=0.1):
time.sleep(delay)
return a + b
# Prepare data
a_list = [1, 2, 3, 4, 5]
b_list = [10, 20, 30, 40, 50]
# Execute in parallel using multiple processes
executor = ProcessExecutor(process, nprocs=4)
results = executor.run(a_list, b_list, delay=0.1)
print(results) # [11, 22, 33, 44, 55]
Executors
Sequential Execution
| Executor | Description |
|---|---|
SequentialExecutor |
Execute tasks sequentially in a single process |
Process-based Executors
| Executor | Description |
|---|---|
ProcessExecutor |
Execute tasks in parallel using multiple processes |
AutoProcessExecutor |
Process executor that automatically falls back to sequential execution when nprocs=1 |
BoundedProcessExecutor |
Process executor with bounded resource slots (e.g., GPU ports) |
AutoBoundedProcessExecutor |
Auto-switching bounded process executor |
Thread-based Executors
| Executor | Description |
|---|---|
ThreadExecutor |
Execute tasks in parallel using a thread pool |
AutoThreadExecutor |
Automatically fallback to sequential execution when nworkers=1 |
Async Executors
| Executor | Description |
|---|---|
AsyncExecutor |
Execute async tasks concurrently in a single process |
AsyncProcessExecutor |
Execute async tasks across multiple processes |
AutoAsyncProcessExecutor |
Auto-switching async process executor |
Parallel Executors (Data Splitting)
| Executor | Description |
|---|---|
TaskParallelExecutor |
Split data and process each item with a single-task function |
BatchParallelExecutor |
Split data and process batches with a batch function |
AutoTaskParallelExecutor |
Auto-switching task parallel executor |
AutoBatchParallelExecutor |
Auto-switching batch parallel executor |
Usage Examples
Using ProcessExecutor
from parallel_iterator import ProcessExecutor
def compute(x, y, op="+"):
if op == "+":
return x + y
return x - y
executor = ProcessExecutor(compute, nprocs=4)
results = executor.run([1, 2, 3], [4, 5, 6], op="+")
# results: [5, 7, 9]
Using ThreadExecutor
from parallel_iterator import ThreadExecutor
def io_task(url, timeout=10):
# Simulate I/O operation
return f"Downloaded: {url}"
executor = ThreadExecutor(io_task, nworkers=8)
results = executor.run(["url1", "url2", "url3"], timeout=5)
Using AsyncExecutor
import asyncio
from parallel_iterator import AsyncExecutor
async def async_task(item, delay=0.1):
await asyncio.sleep(delay)
return item * 2
executor = AsyncExecutor(async_task)
results = executor.run([1, 2, 3, 4, 5], delay=0.1)
# results: [2, 4, 6, 8, 10]
Using BatchParallelExecutor
from parallel_iterator import BatchParallelExecutor
def process_batch(items_a, items_b, factor=1):
return [a + b * factor for a, b in zip(items_a, items_b)]
executor = BatchParallelExecutor(process_batch, nprocs=4)
results = executor.run([1, 2, 3, 4], [10, 20, 30, 40], factor=2)
# results: [21, 42, 63, 84]
Executor Selection Guide
| Scenario | Recommended Executor |
|---|---|
| CPU-bound tasks | ProcessExecutor |
| I/O-bound tasks | ThreadExecutor or AsyncExecutor |
| Need GPU/port binding | BoundedProcessExecutor |
| Async functions + multiprocessing | AsyncProcessExecutor |
| Batch data processing | BatchParallelExecutor |
| Single-task function + data splitting | TaskParallelExecutor |
| Uncertain about process count | Use Auto* series executors |
API Reference
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for parallel-iterator 1.0.0
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 |
|---|---|---|---|---|
| parallel_iterator-1.0.0.tar.gz | 11.9 kB | Without provenance | Details for parallel_iterator-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| parallel_iterator-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for parallel_iterator-1.0.0-py3-none-any.whl |
Total release size: 21.5 kB
Release files / parallel_iterator-1.0.0.tar.gz
| Download URL | parallel_iterator-1.0.0.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1d8364d15621cf7f1e8fefc26f4220598c58024c59075a6155883c85cab154d
|
|
BLAKE2b-256 checksum How to use checksums |
290a85098955b232b39fad7c0dcb06d2fffe2db24bd4aec9e781a02c8888ab7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / parallel_iterator-1.0.0-py3-none-any.whl
| Download URL | parallel_iterator-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d091fd94b4203b895de347c5806c54d23cab758a85bcd529f004b651577f3295
|
|
BLAKE2b-256 checksum How to use checksums |
767f9415cb5c136fc6af15ac1abbbc872edd478337fa2f65e84c0d010eebd9b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for parallel-iterator 1.0.0
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.