Registry / data / mpire
library2.10.2pypypi✓ verified 24d ago

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.

pip install mpire
INSTALL
IMPORT
SIG · MPIRE
M
mpire
datapythonv2.10.2
Install
2.3s avg
Import
431ms
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.10.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.446s · 28.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.3s · import 0.416s · 29MB
27MB installed
● package 27MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WorkerPool
from mpire import WorkerPool
from multiprocessing import Pool
MPIRE's core class is `WorkerPool`, which extends `multiprocessing.Pool` with additional features and a different API. Directly using `multiprocessing.Pool` will not provide MPIRE's enhancements.

This quickstart demonstrates how to use `mpire.WorkerPool` to parallelize a simple function across multiple processes. It initializes a pool with 4 workers and uses the `map` function, similar to Python's built-in `map` but executed in parallel.

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]}...")
Debug
Known issues
breakingThe `func_pointer` parameter in `map` functions was renamed to `func`.
fix
Update your code to use `func` instead of `func_pointer` when calling `WorkerPool.map`, `map_unordered`, `imap`, or `imap_unordered`.
affects: >=2.0.0
deprecatedThe `restart_workers` parameter was deprecated and subsequently removed.
fix
Remove the `restart_workers` parameter. Consider using `worker_lifespan` in the `WorkerPool` constructor for similar functionality of restarting workers after a specified number of tasks.
affects: Deprecated in <1.0.0, removed in >=1.0.0
deprecatedThe `enable_insights` parameter moved from `map` functions to the `WorkerPool` constructor.
fix
Pass `enable_insights=True` to the `WorkerPool` constructor instead of individual `map` calls.
affects: Deprecated in >=2.3.0, removed in >=2.6.0
gotchaCopy-on-write shared objects, a key performance feature, are only available when using the `fork` start method, which is not supported on Windows.
fix
On Windows, shared objects will be copied once per worker instead of using copy-on-write. This might still be more efficient than copying per task, but understand the performance implications compared to Linux/macOS.
affects: All versions
gotchaMixing multiple `map` calls (e.g., `pool.map` followed by `pool.imap`) can raise an error due to internal state management.
fix
Avoid mixing different types of `map` calls within the same `WorkerPool` instance. If you need to use different map styles, create separate `WorkerPool` instances for each.
affects: >=2.7.0
gotchaWhen using `dill` as the serialization backend on Windows, exceptions raised by workers or exit functions might print additional `OSError` messages to the terminal.
fix
These `OSError` messages can generally be safely ignored as they are related to internal cleanup processes.
affects: All versions with `dill` on Windows
gotchaThe progress bar feature is not supported when using the `threading` start method on Windows.
fix
If running on Windows and needing a progress bar, use a different start method (e.g., `spawn` or `forkserver` if available, though `fork` is not on Windows) or consider disabling the progress bar.
affects: All versions
Errors
Common errors & fixes
AttributeError: Can't get attribute '<some_function>' on <module '__main__' (built-in)>
This error, or a more general 'PicklingError: Can't pickle...', occurs when trying to parallelize a function or pass an object that Python's `pickle` module cannot serialize. `mpire` uses `pickle` for inter-process communication, and functions defined locally (e.g., within another function, a method, or interactively in a Jupyter/IPython session) or complex objects might not be picklable, especially with 'spawn' or 'forkserver' start methods.
fix
Define the function at the top-level of a module so it's globally accessible and picklable. Alternatively, set `use_dill=True` in the `WorkerPool` constructor (e.g., `with WorkerPool(use_dill=True) as pool:`) to use `dill` as the serialization backend, which can handle more complex Python objects, including local functions and lambdas.
ModuleNotFoundError: No module named 'mpire'
The `mpire` package is not installed in the Python environment, or the Python interpreter cannot locate it in its search path.
fix
Install the `mpire` package using pip: `pip install mpire`.
ImportError: IProgress not found. Please update jupyter and ipywidgets.
This error occurs when `mpire` attempts to display a progress bar in a Jupyter notebook environment, but the `ipywidgets` package is either not installed or not properly enabled.
fix
Install `ipywidgets` using pip (`pip install ipywidgets`) or conda (`conda install -c conda-forge ipywidgets`). If the issue persists, enable the Jupyter nbextension by running `jupyter nbextension enable --py --sys-prefix widgetsnbextension` and then restart your Jupyter notebook server.
UserWarning: semaphore_tracker: There appear to be X leaked semaphores to clean up at shutdown
This warning, often seen after a `KeyboardInterrupt` or an error, indicates that `multiprocessing`'s semaphore tracker is reporting unreleased semaphores. This can happen when `mpire`'s internal task or results queues become very full, causing a delay in graceful shutdown and resource cleanup.
fix
When using lazy map functions (e.g., `imap`), ensure you iterate through all results to drain the queue. To prevent queues from becoming overly full and speed up shutdown, utilize the `max_tasks_active` parameter in the `WorkerPool` constructor (e.g., `with WorkerPool(max_tasks_active=n_jobs * 2) as pool:`).
Upgrade
Version history
2.10.2latest on PyPI · released May 7, 2024
Audit
Dependencies
tqdmrequiredProvides progress bar functionality.
pygmentsrequiredUsed for code highlighting in some features (e.g., dashboard).
pywin32requiredRequired for Windows-specific features.
importlib_resourcesrequiredRequired for Python versions prior to 3.9.
dilloptionalOptional serialization backend through `multiprocess`, enabling parallelizing more exotic objects (e.g., lambdas, nested functions).
FlaskoptionalOptional dependency for the MPIRE dashboard feature.
Agent activity
5 hits · last 30 days
node
4
Resources
mpire — pip install mpire · libregistry