Efficient parallel task scheduling and concurrency management
Project description
parallelism
Unlock advanced task scheduling in Python with parallelism
.
Seamlessly coordinate parallel and concurrent execution, optimizing performance while ensuring code integrity.
Embrace expert scheduling techniques to elevate your programming to new heights of efficiency and responsiveness.
Installation
You can install this package using pip:
pip install parallelism
Basic Usage
Explore an effortless approach to task creation and management. Follow these steps to get started:
- Import the necessary classes and functions in your Python code.
# Built-in modules
from multiprocessing import Process
from threading import Thread
# Third-party libraries
from parallelism import scheduled_task, task_scheduler
- Define your task functions. These user-defined functions will be executed in parallel and concurrently.
def func(*args, **kwargs):
if not args and not kwargs:
raise ValueError('Missing *args or **kwargs')
return args, kwargs
- Create task instances using the
scheduled_task
function, specifying the execution unit (Process or Thread), task name, function, and provide any required positional or keyword arguments.
task1 = scheduled_task(Process, 'task1', func, args=(1, 2, 3), continual=True)
task2 = scheduled_task(Process, 'task2', func, kwargs={'a': 10, 'b': 20}, continual=True)
task3 = scheduled_task(Thread, 'task3', func, continual=True)
- Schedule tasks using the
task_scheduler
function, Specify the tasks to be executed along with the desired number of processes and threads.
result = task_scheduler(tasks=(task1, task2, task3), 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
{
'task1': datetime.datetime(%Y, %m, %d, %H, %M, %S, %f),
'task2': datetime.datetime(%Y, %m, %d, %H, %M, %S, %f),
'task3': datetime.datetime(%Y, %m, %d, %H, %M, %S, %f),
}
>>> result.elapsed_time
{
'task1': float(...),
'task2': float(...),
'task3': float(...),
}
>>> result.raise_exception
{
'task3': ValueError('Missing *args or **kwargs'),
}
>>> result.return_value
{
'task1': ((1, 2, 3), {}),
'task2': ((), {'a': 10, 'b': 20}),
}
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
File details
Details for the file parallelism-0.1.4.tar.gz
.
File metadata
- Download URL: parallelism-0.1.4.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a751d6206fc90f5903566fe19bbcb2d20bb3bafd4237630ad921804a5970c303 |
|
MD5 | eed8ef8a0639d7a226ad5a01b6ef21a5 |
|
BLAKE2b-256 | 4c1a2d0cc085b1d24d8b1049b3d8c8e959c2742421b44fddecb789bcc5336177 |
File details
Details for the file parallelism-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: parallelism-0.1.4-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d97bd8c5b6062a4cf5b59a01acbfe26b3f1a8450277782f326bc5b781413f427 |
|
MD5 | 5d49ad1d3570e1c11b9989eb19b083be |
|
BLAKE2b-256 | 8299f2e5cba4c730e681baa3ed93d198cf1ab0ba18e810cff4d2680d67ed0b5c |