Skip to main content

简便的多进程调用工具,基于 concurrent.futures.ProcessPoolExecutor 的封装

Project description

Util Process Pool

简便的多进程调用工具,基于 concurrent.futures.ProcessPoolExecutor 的封装。

特性

  • 🚀 简化的多进程调用接口
  • 📊 进度跟踪和错误处理
  • 🔧 灵活的配置选项
  • 📝 详细的日志记录
  • 🎯 支持多种任务类型(CPU密集型、IO密集型)

安装

pip install util-process-pool

快速开始

基本使用

from util_process_pool import parallel_map

# 简单的并行计算
numbers = list(range(10))
results = parallel_map(lambda x: x * x, numbers)
print(results)  # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

使用 ProcessPool 类

from util_process_pool import ProcessPool

def process_data(data):
    # 处理数据的函数
    return data * 2

with ProcessPool(max_workers=4) as pool:
    data_list = [1, 2, 3, 4, 5]
    results = list(pool.map(process_data, data_list))
    print(results)  # [2, 4, 6, 8, 10]

批量执行复杂任务

from util_process_pool import batch_execute

def complex_task(param1, param2):
    # 复杂的处理逻辑
    return f"Processed: {param1} + {param2}"

# 准备参数列表
args_list = [
    (("hello", "world"),),  # 第一个任务
    (("foo", "bar"),),      # 第二个任务
]

results = batch_execute(complex_task, args_list, show_progress=True)

API 文档

ProcessPool 类

主要的进程池管理类。

ProcessPool(
    max_workers=None,      # 最大工作进程数(默认:CPU核心数)
    initializer=None,      # 进程初始化函数
    initargs=(),           # 初始化函数参数
    logger=None            # 自定义日志记录器
)

方法:

  • submit(func, *args, **kwargs): 提交单个任务
  • map(func, iterable, timeout=None, chunksize=1): 并行映射
  • execute_batch(func, args_list, timeout=None, show_progress=False): 批量执行
  • wait_completion(timeout=None): 等待所有任务完成

工具函数

  • parallel_map(func, iterable, max_workers=None, chunksize=1, timeout=None)
  • batch_execute(func, args_list, max_workers=None, timeout=None, show_progress=False)

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

util_process_pool-0.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

util_process_pool-0.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file util_process_pool-0.0.0.tar.gz.

File metadata

  • Download URL: util_process_pool-0.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.7

File hashes

Hashes for util_process_pool-0.0.0.tar.gz
Algorithm Hash digest
SHA256 4bacd88319b2f362c234c0bc437c5521a950ad484583734ed4eff7b18fdce828
MD5 78ca0cfadca0463fb8879598dd06964e
BLAKE2b-256 1dc1bf5a9efea9105219d4379fbbec31ef0342add752de6cf3faec71048d74cf

See more details on using hashes here.

File details

Details for the file util_process_pool-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for util_process_pool-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 016ce413ab9e224f85713e862dd13d8fca2bc05b86eb0cb919f6aff06ab2cf84
MD5 b929142ca61adb1832c4a2b2275055de
BLAKE2b-256 4309703d0298713a753da2f75270ed3e1671ec2b80eb09e55f89ba9e5254f406

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page