Skip to main content

tqdmp

License MIT PyPI Python Version Unit Tests codecov

Multiprocessing with tqdm progressbars!

Did you feel like you are missing a progressbar when using doing multiprocessing with pool.map? Well no more! tqdmp is an easy to use wrapper for pool.map but with a tqdm progressbar. Moreover it supports some nice usecases making multiprocessing much simpler:

  • Use multiple iterables by simply packing them as a tuple
  • Unpack the function output of the parallized function in case it returns multiple variables
  • Switch to single processing by setting the number of processes to None or 0
  • Pass additional constant variables to the parallized function as kwargs

Examples of these usecases are given in section Examples.

Installation

You can install tqdmp via pip:

pip install tqdmp

Examples

In the following we demonstrate the general useage of tqdmp and some useful features.

Default multiprocessing

Using pool.map:

from multiprocessing import Pool

def function(index):
    return index * 10

pool = Pool(2)
result = pool.map(function, range(10))
print(f"pool.map: {result}")

Using tqdmp:

from tqdmp import tqdmp

def function(index):
    return index * 10

result = tqdmp(function, range(10), 2)
print(f"tqdmp: {result}")

Multiple iterables

Using pool.map:

from multiprocessing import Pool

def function(input_tuple):
    index1, index2 = input_tuple
    return index1 * index2

pool = Pool(2)
result = pool.map(function, zip(range(10), range(10)))
print(f"pool.map: {result}")

Using tqdmp:

from tqdmp import tqdmp

def function(index1, index2):
    return index1 * index2

result = tqdmp(function, (range(10), range(10)), 2, mult_iter=True)
print(f"tqdmp: {result}")

Multiple outputs

Using pool.map:

from multiprocessing import Pool

def function(index1):
    return index1, index1 * 10

pool = Pool(2)
result = pool.map(function, range(10))
result1, result2  = map(list, zip(*result))
print(f"pool.map result1: {result1}")
print(f"pool.map result2: {result2}")

Using tqdmp:

from tqdmp import tqdmp

def function(index1):
    return index1, index1 * 10

result1, result2 = tqdmp(function, range(10), 2, mult_out=True)
print(f"tqdmp result1: {result1}")
print(f"tqdmp result2: {result2}")

Switching between single- and multiprocessing

Using pool.map:

from multiprocessing import Pool

def function(index):
    return index * 10

num_processes = None  # None or 0 for single, >0 for multi
iterable = range(10)

if (num_processes is None) or (num_processes == 0):
    result = [function(index) for index in iterable]
else:
    pool = Pool(num_processes)
    result = pool.map(function, iterable)
print(f"pool.map: {result}")

Using tqdmp:

from tqdmp import tqdmp

def function(index):
    return index * 10

result = tqdmp(function, range(10), None)  # None or 0 for single, >0 for multi
print(f"tqdmp: {result}")

Passing additional constant variables

Using pool.map:

from multiprocessing import Pool
from functools import partial

def function(index, const1, const2):
    return (index * const1) + const2

pool = Pool(2)
partial_func = partial(function, const1=5, const2=7)
result = pool.map(partial_func, range(10))
print(f"pool.map: {result}")

Using tqdmp:

from tqdmp import tqdmp

def function(index, const1, const2):
    return (index * const1) + const2

result = tqdmp(function, range(10), 2, const1=5, const2=7)
print(f"tqdmp: {result}")

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, "tqdmp" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Metadata

Release files for tqdmp 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tqdmp 0.0.3
File Size Uploaded
tqdmp-0.0.3.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tqdmp 0.0.3
File Interpreter ABI Platform
tqdmp-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / tqdmp-0.0.3.tar.gz

Download URL tqdmp-0.0.3.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0f61ad293b6d0f4a9940c14c670a003abddfe30023e914f81eb81128f0227c10
BLAKE2b-256 checksum
How to use checksums
81ea714796ea20800a75c1adbcc6452a3c06a393eb6d86be624898363f5054ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tqdmp-0.0.3-py3-none-any.whl

Download URL tqdmp-0.0.3-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17a27f56ad8db566329fae8e6663bf78b7bde892f17cfaa6de0f80134d568fc9
BLAKE2b-256 checksum
How to use checksums
9b1aa4ab895fec65f65bc3ca892608782da8783a4b45c7e9b840512a905f9acd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page