A Python library to maximise CPU usage by smartly sharing threads among multiple functions.
Systems with a limited number of cores, like the Raspberry Pi, struggle with CPU resource constraints, making it challenging to efficiently execute multiple tasks functions.
ThreadShare is an Python library designed to efficiently utilize a single CPU core by dynamically sharing threads among multiple functions. It adapts to the execution rates and computational loads of tasks to ensure optimal performance.
- Thread Loop Sharing: Run multiple functions at different rates on shared threads.
- Dynamic Thread Management: Automatically manages thread creation and load balancing.
- Adaptive Load Balancing: Dynamically allocate tasks to threads based on their load.
- Rate-Based Task Scheduling: Schedules tasks based on their execution rates.
- Resource Monitoring: Monitors CPU and memory usage to adaptively manage thread utilization.
- Graceful Shutdown: Ensures all tasks are completed before shutting down.
To install ThreadShare, you can use pip:
pip install ThreadShare
Here is a basic example to demonstrate how to use ThreadShare:
from ThreadShare import ThreadManager
# Define your function
def example_task():
print("Task executed.")
# Initialize ThreadManager
manager = ThreadManager()
# Add tasks
manager.add_task(example_task, rate=0.2)
# Shutdown (optional)
manager.shutdown()
ThreadShare provides real-time metrics and resource monitoring. These metrics can be accessed programmatically for advanced use-cases or can be logged for monitoring and debugging.
This project is licensed under the MIT License - see the LICENSE.md file for details.