Skip to main content

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:

  1. 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
  1. Define your task functions. These functions will be executed concurrently:
def func(*args, **kwargs):
    # Your task logic here
    pass
  1. 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={...})
  1. 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)
  1. 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

parallelism-0.1.3.tar.gz (21.3 kB view hashes)

Uploaded Source

Built Distribution

parallelism-0.1.3-py3-none-any.whl (21.3 kB view hashes)

Uploaded Python 3

Supported by

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