p_tqdm is a Python library that simplifies parallel processing by wrapping `pathos.multiprocessing` with `tqdm` progress bars. It provides a flexible parallel map functionality, supporting lambda functions, nested functions, and class methods, while displaying a clear progress bar with estimated time to completion. The library is actively maintained, with version 1.4.2 being the current release as of August 2024, and receives updates to ensure compatibility and address issues.
pip install p-tqdmVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `p_map` to apply a function in parallel to elements from multiple iterables, displaying a progress bar. The `my_function` simulates a task by sleeping briefly and then adding two numbers.
Upgrade your Python interpreter to 3.5+ or use p_tqdm v1.3 or higher. `pip install --upgrade p-tqdm`.
For single, repeated arguments, use `functools.partial`. For example, instead of `p_map(func, iterable, fixed_arg)`, use `p_map(partial(func, fixed_arg=fixed_arg), iterable)`.
Use `tqdm.write('Your message')` instead of `print()` to ensure messages are printed without interfering with the progress bar.Pass the `total` keyword argument to `p_map` (or other `p_tqdm` functions) with the expected number of iterations: `p_map(func, iterable, total=expected_count)`.
Ensure the function passed to `p_tqdm` is a top-level function. If using class methods, convert them to static or standalone functions, or ensure the class itself is picklable. Consider using `multiprocess.Pool` with `tqdm.tqdm` manually if `p_tqdm`'s `pathos` integration proves problematic for complex objects, or simplify the function being pickled.
Upgrade `p-tqdm` to version 1.4.0 or higher: `pip install --upgrade p-tqdm`. This version includes a fix for `collections` compatibility with Python 3.9+.