ahvn.utils.basic.parallel_utils module

class ahvn.utils.basic.parallel_utils.Parallelized(func, args=None, num_threads=None, desc=None, progress=None)[源代码]

基类:object

参数:
__init__(func, args=None, num_threads=None, desc=None, progress=None)[源代码]

Initialize a parallelized task executor with progress tracking.

参数:
  • func (Callable) -- The function to execute in parallel (should always accept kwargs only).

  • args (Iterable[Dict[str, Any]]) -- Iterable of argument dictionaries to pass as kwargs.

  • num_threads (Optional[int]) -- Number of worker threads. Defaults to None, which uses unlimited threads as per ThreadPoolExecutor.

  • desc (Optional[str]) -- Description for the progress bar. Defaults to None.

  • progress (Optional[Type[Progress]]) -- Progress class to use. Defaults to TqdmProgress.

__enter__()[源代码]

Enter the runtime context related to this object.

返回:

The Parallelized instance itself, which can be iterated over to yield results.

返回类型:

self

Usage:
with Parallelized(func, args) as ptasks:

ptasks.progress.set_description("Processing tasks") for args, result, error in ptasks:

...

property progress: Progress

Access the progress bar.

property pbar: Progress

Alias for progress (backward compatibility).