Enhance Parallel Task Execution
Project description
parallelism
The Parallelism library offers a powerful set of tools for managing concurrent task execution using both processes and threads. It aims to simplify the development of parallel programs, providing a higher-level interface for distributing tasks across multiple execution units. Whether your tasks are CPU-bound or I/O-bound, the Parallelism library facilitates efficient and streamlined parallel processing.
Installation
You can install the Parallelism library using pip:
pip install parallelism
Basic Usage
The Parallelism library offers an intuitive way to create and manage tasks for concurrent execution. Here's a simple example of how to use the library:
- Import the necessary modules and classes in your Python code:
from multiprocessing import Process
from threading import Thread
from parallelism import scheduled_task, task_scheduler
- Define your task functions. These functions will be executed concurrently:
def func(*args, **kwargs):
# Your task logic here
pass
- Create task instances using the
scheduled_task
function, specifying the execution unit (Process or Thread), task name, function, and positional arguments or keyword arguments:
task1 = scheduled_task(Process, 'task1', func, args=(...))
task2 = scheduled_task(Thread, 'task2', func, kwargs={...})
- Schedule tasks using the
task_scheduler
function, indicating the tasks to be executed and the desired number of processes and threads:
result = task_scheduler(tasks=(task1, task2), processes=2, threads=4)
- Access task execution details and results through the result object, providing insights into execution times, elapsed times, exceptions, and return values:
result.execution_time
result.elapsed_time
result.raise_exception
result.return_value
For more comprehensive documentation and advanced usage, please refer to the full API Documentation.
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
Built Distribution
Hashes for parallelism-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 372bc4a2b033bd2528a65b310ee6ca9dfede6d27005ae27ab209e63bd968db1e |
|
MD5 | 61348e59b0491a558134b51bb7ed22f0 |
|
BLAKE2b-256 | 9fdfe872810c9d45f8adf8c77b0e8c45f942cd0126600503e59b0ac35383a733 |