ParallelFunction (_parallel/_decorator.py)

python-progressbar · progressbar/_parallel/_decorator.py · python · BSD-3-Clause
email

A decorator that attaches parallel batch verbs (map, imap, starmap, async variants) to a plain function with configurable worker pools.

# Source: https://github.com/wolph/python-progressbar | License: BSD-3-Clause | Copyright 2022, Rick van Hattem (Wolph)
# Provided via justclaw.it.com; keep this notice with the code.
"""`@parallel`: attach the batch verbs to a plain function.

Sugar over the module verbs::

    @progressbar.parallel(workers=4, pool='process')
    def crunch(path: str) -> Result: ...


    crunch(one_path)  # unchanged direct call
    crunch.map(paths)  # parallel + bar, decorator config applied

The decorator returns the *original function object* with bound verbs
attached as attributes. That shape is deliberate: pickling by
qualified name stays intact (``pool='process'`` needs it), and spawn's
re-import just re-runs the decoration.
"""

from __future__ import annotations

import functools
import inspect


... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key