CD Multi Tasker
cd_multi_tasker is a Python package designed to handle multiple concurrent tasks efficiently. It supports both CPU-bound and I/O-bound tasks, using multiprocessing for CPU-intensive operations and multithreading for I/O-bound operations.
Features
- Multiprocessing for CPU-bound tasks such as file processing.
- Multithreading for I/O-bound tasks such as HTTP requests.
- Easy-to-use interface for running concurrent tasks.
Installation
To install the package, use:
pip install cd_multi_tasker
Usage
Importing the Package
from cd_multi_tasker import MultiTasking
Example: CPU-bound Tasks (File Processing)
# Initialize the MultiTasking class
multitasker = MultiTasking(max_workers=4)
# Define a sample task function for file processing
def process_file(file_path):
"""
Dummy function to simulate file processing.
Replace with actual file processing logic.
Parameters:
file_path (str): Path to the file to process.
Returns:
str: Dummy result message.
"""
return f"Processed file {file_path}"
# List of file paths to process
file_paths = ["/path/to/file1", "/path/to/file2", "/path/to/file3"]
# Run the tasks
results = multitasker.run_cpu_bound_tasks(file_paths, process_file)
print("File processing results:", results)
Example: I/O-bound Tasks (HTTP Requests)
# Initialize the MultiTasking class
multitasker = MultiTasking(max_workers=4)
# Define a sample task function for HTTP requests
def fetch_data(url):
"""
Dummy function to simulate fetching data from a URL.
Replace with actual HTTP request logic.
Parameters:
url (str): URL to fetch data from.
Returns:
str: Dummy response message.
"""
return f"Fetched data from {url}"
# List of URLs to fetch data from
urls = ["http://example.com/data1", "http://example.com/data2"]
# Run the tasks
results = multitasker.run_io_bound_tasks(urls, fetch_data)
print("HTTP fetching results:", results)
Class and Methods
MultiTasking
__init__(self, max_workers)
- Initializes the MultiTasking class with the maximum number of workers.
- Parameters:
max_workers(int): Maximum number of concurrent tasks.
run_cpu_bound_tasks(self, tasks, task_func, *args, **kwargs)
- Executes multiple CPU-bound tasks concurrently using multiprocessing.
- Parameters:
tasks(list): List of tasks to be processed (e.g., file paths for processing).task_func(callable): Function to run for each task.*args: Variable length argument list for the task function.**kwargs: Arbitrary keyword arguments for the task function.
- Returns:
list: Results of the tasks.
run_io_bound_tasks(self, tasks, task_func, *args, **kwargs)
- Executes multiple I/O-bound tasks concurrently using multithreading.
- Parameters:
tasks(list): List of tasks to be processed (e.g., URLs for web requests).task_func(callable): Function to run for each task.*args: Variable length argument list for the task function.**kwargs: Arbitrary keyword arguments for the task function.
- Returns:
list: Results of the tasks.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
More Info
For more information, visit codedocta.com.
Metadata
Release files for cd-multi-tasker 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cd_multi_tasker-0.1.2.tar.gz | 3.5 kB | Without provenance | Details for cd_multi_tasker-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cd_multi_tasker-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for cd_multi_tasker-0.1.2-py3-none-any.whl |
Total release size: 8.6 kB
Release files / cd_multi_tasker-0.1.2.tar.gz
| Download URL | cd_multi_tasker-0.1.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95e2d4d8ef6417efc73c599e1b7e049ba5ffa81ff8fe14f2d4729af1d9269516
|
|
BLAKE2b-256 checksum How to use checksums |
a307a472b710d9c75bde993765f64f3be3e65ddad76dd1f1c2b82520bd9a53e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.7 Windows/10
|
Release files / cd_multi_tasker-0.1.2-py3-none-any.whl
| Download URL | cd_multi_tasker-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
642c5bc397e603918a7f3324aaf25c9f40be5239a2f7da5be7210bea585de9ab
|
|
BLAKE2b-256 checksum How to use checksums |
2624b37c3bbbd8407ab9bc82bfd0a3005b34826d22b880b58e95fa3f1f1dc2a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.7 Windows/10
|
Security for cd-multi-tasker 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.