MPIRE - MultiProcessing Is Really Easy
MPIRE is a Python package that simplifies multiprocessing, offering a faster and more user-friendly alternative to the standard `multiprocessing` module. It provides an intuitive API with map-like functions, support for worker state, progress bars (via tqdm), worker insights, and efficient handling of shared objects. The library is actively maintained with regular updates and aims to make parallelizing CPU-bound tasks straightforward and performant.
Warnings
- breaking The `func_pointer` parameter in `map` functions was renamed to `func`.
- deprecated The `restart_workers` parameter was deprecated and subsequently removed.
- deprecated The `enable_insights` parameter moved from `map` functions to the `WorkerPool` constructor.
- gotcha Copy-on-write shared objects, a key performance feature, are only available when using the `fork` start method, which is not supported on Windows.
- gotcha Mixing multiple `map` calls (e.g., `pool.map` followed by `pool.imap`) can raise an error due to internal state management.
- gotcha When using `dill` as the serialization backend on Windows, exceptions raised by workers or exit functions might print additional `OSError` messages to the terminal.
- gotcha The progress bar feature is not supported when using the `threading` start method on Windows.
Install
-
pip install mpire
Imports
- WorkerPool
from mpire import WorkerPool
Quickstart
import time
from mpire import WorkerPool
def my_function(x):
time.sleep(0.01) # Simulate some work
return x * 2
# Run with 4 worker processes
with WorkerPool(n_jobs=4) as pool:
results = pool.map(my_function, range(100))
print(f"Results: {results[:5]}...")