Skip to content

A Python library to maximise CPU usage by smartly sharing threads among multiple functions

License

Notifications You must be signed in to change notification settings

benjamincham/ThreadShare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThreadShare


ThreadShare Logo


A Python library to maximise CPU usage by smartly sharing threads among multiple functions.

Why ThreadShare ?

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.

Key Features

  • 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.

Installation

To install ThreadShare, you can use pip:

pip install ThreadShare

Usage

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()

Metrics and Monitoring

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.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

A Python library to maximise CPU usage by smartly sharing threads among multiple functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages