项目作者: JPLeoRX

项目描述 :
Parallel execution of your tasks simplified! Analog to concurrent.futures executors
高级语言: Python
项目地址: git://github.com/JPLeoRX/parallelizer.git
创建时间: 2021-05-14T15:06:54Z
项目社区:https://github.com/JPLeoRX/parallelizer

开源协议:MIT License

下载


parallelizer

Parallel execution of your tasks simplified! This package can be used as an alternative to Python’s concurrent.futures executors, or as an analog of Java’s ExecutorService.

Two simple wrappers (thread-based and process-based), that allow for easy split and parallel processing of your jobs.

Description

This package provides two classes:

  • ThreadParallelizer to execute your jobs in new threads
  • ProcessParallelizer to execute your jobs in new processes

This is a pure python implementation, with usage of threading and multiprocessing packages

Note that the wrappers appear to be in sync (from the caller’s perspective), they will wait until all inner tasks are completed.

Installation

Normal installation

  1. pip install parallelizer

Development installation

  1. git clone https://github.com/jpleorx/parallelizer.git
  2. cd parallelizer
  3. pip install --editable .

Example

  1. import time
  2. from parallelizer import ThreadParallelizer, ProcessParallelizer, repeat
  3. def power_function(base: int, power: int) -> int:
  4. time.sleep(1)
  5. return base ** power
  6. inputs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  7. number_of_threads = 5
  8. thread_parallelizer = ThreadParallelizer(number_of_threads)
  9. results = thread_parallelizer.execute(power_function, [inputs, repeat(2, len(inputs))])
  10. process_parallelizer = ProcessParallelizer(number_of_threads)
  11. results = process_parallelizer.execute(power_function, [inputs, repeat(2, len(inputs))])