Adaptive thread pool executor with dynamic scaling policies
Project description
Adaptive Executor
Adaptive thread pool executor that scales concurrency based on policies.
Features
- Time-based scaling
- CPU & memory criteria
- Multi-criterion aggregation
- Graceful shutdown
Installation
Minimal Installation (Core Only)
pip install adaptive-executor
Feature-Specific Installations
# Time-based scaling only
pip install adaptive-executor[time]
# CPU/Memory monitoring only
pip install adaptive-executor[cpu]
# Complete feature set (recommended)
pip install adaptive-executor[standard]
# Development with all tools
pip install adaptive-executor[dev]
Quick Start
from adaptive_executor import AdaptiveExecutor, MultiCriterionPolicy
from adaptive_executor.criteria import TimeCriterion, CpuCriterion
from datetime import time
# Create scaling criteria
time_policy = TimeCriterion(
worker_count=8,
active_start=time(22, 0),
active_end=time(6, 0),
timezone="UTC",
)
cpu_policy = CpuCriterion(threshold=75, workers=4)
# Combine criteria
policy = MultiCriterionPolicy([time_policy, cpu_policy], hard_cap=10)
# Create and use executor
executor = AdaptiveExecutor(max_workers=15, policy=policy)
# Submit tasks
def my_task(task_id):
print(f"Processing task {task_id}")
for i in range(5):
executor.submit(my_task, i)
executor.join()
executor.shutdown()
Development Setup
This project uses setuptools with a src/ package layout (src/adaptive_executor).
git clone https://github.com/Teut2711/adaptive-executor.git
cd adaptive-executor
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e ".[dev]"
Logging Configuration
The adaptive-executor provides comprehensive logging that can be configured to suit your needs. By default, it logs to the console with INFO level.
Basic Logging Control
from adaptive_executor import setup_logger
# Disable all logging
setup_logger(level=logging.CRITICAL)
# Or set a specific log level
import logging
setup_logger(level=logging.WARNING) # Only show warnings and above
Advanced Logging Configuration
You can also configure file logging with rotation:
# Configure file logging with rotation (10MB per file, keep 5 backups)
setup_logger(
level=logging.DEBUG,
log_file="/var/log/adaptive_executor.log",
max_bytes=10*1024*1024, # 10MB
backup_count=5
)
Environment Variables
You can control logging via environment variables:
# Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
ADAPTIVE_EXECUTOR_LOG_LEVEL=WARNING
# Enable file logging
ADAPTIVE_EXECUTOR_LOG_FILE=/path/to/logfile.log
# Set max log file size (in bytes)
ADAPTIVE_EXECUTOR_LOG_MAX_BYTES=10485760 # 10MB
# Set number of backup files to keep
ADAPTIVE_EXECUTOR_LOG_BACKUP_COUNT=5
Disabling Logging Completely
To completely disable all logging:
import logging
logging.getLogger('adaptive_executor').addHandler(logging.NullHandler())
logging.getLogger('adaptive_executor').propagate = False
Documentation
Full documentation is available at https://Teut2711.github.io/adaptive-executor
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adaptive_executor-0.1.1.tar.gz.
File metadata
- Download URL: adaptive_executor-0.1.1.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee27adbc6ff626fbda9d5d46d66fc0d22e52bc829fc6d0713addd54093c6299e
|
|
| MD5 |
8e9a1e0f2f7f8c346e26ec8ee2ce90de
|
|
| BLAKE2b-256 |
c8ce3ffb501aa4c7fc49ad79e8f8f6a75470e52fd80c7c10f907548b6f55dd5c
|
Provenance
The following attestation bundles were made for adaptive_executor-0.1.1.tar.gz:
Publisher:
publish.yaml on Teut2711/adaptive-executor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adaptive_executor-0.1.1.tar.gz -
Subject digest:
ee27adbc6ff626fbda9d5d46d66fc0d22e52bc829fc6d0713addd54093c6299e - Sigstore transparency entry: 1105626894
- Sigstore integration time:
-
Permalink:
Teut2711/adaptive-executor@618876f93d34f7bd85f055db6aa1743036a2b6fd -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Teut2711
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@618876f93d34f7bd85f055db6aa1743036a2b6fd -
Trigger Event:
push
-
Statement type:
File details
Details for the file adaptive_executor-0.1.1-py3-none-any.whl.
File metadata
- Download URL: adaptive_executor-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a53568352a49eea34b9866a95693cd130d5b27778be1b44623e25cc45c9f492
|
|
| MD5 |
4d8493381afcf5fc1450cacc9db3f0bb
|
|
| BLAKE2b-256 |
3fa408ec9a5ba6c0e8132f06f2717fd3465520fe08720d654e76d8d39ca1c74a
|
Provenance
The following attestation bundles were made for adaptive_executor-0.1.1-py3-none-any.whl:
Publisher:
publish.yaml on Teut2711/adaptive-executor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adaptive_executor-0.1.1-py3-none-any.whl -
Subject digest:
9a53568352a49eea34b9866a95693cd130d5b27778be1b44623e25cc45c9f492 - Sigstore transparency entry: 1105627020
- Sigstore integration time:
-
Permalink:
Teut2711/adaptive-executor@618876f93d34f7bd85f055db6aa1743036a2b6fd -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Teut2711
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@618876f93d34f7bd85f055db6aa1743036a2b6fd -
Trigger Event:
push
-
Statement type: