Auto-selecting thread/process pool utilities.
Project description
smartpool
Auto-selecting thread/process pool utilities for parameterized tasks.
✨ Why smartpool
smartpool provides a single entry point to run parameterized tasks with either a thread pool or a process pool. It keeps the API small, chooses a sensible executor in auto mode, and stays close to the stdlib so you can drop it into existing scripts.
🎯 Target users & scope
Smartpool is designed for lightweight batch execution in scripts and services where you want a small, predictable API.
- Best for: IO-heavy tasks, CPU-heavy tasks, short batch jobs
- Not for: distributed scheduling, persistent queues, complex retry pipelines
✅ Features
- Unified interface for thread/process pools
automode picks a reasonable executor for the runtime- Ordered or completion-order results
- Timeout control per task and per run
- Lightweight stats collection via
RunStats - Resource guard with
max_tasks - PEP 561 typing with
py.typed
📦 Installation
pip install smartpool
🚀 Quickstart
from smartpool import ThreadUtils
def work(x: int) -> int:
return x * 2
result = ThreadUtils.run_parameterized_task(
work,
[1, 2, 3, 4],
mode="auto",
ordered=True,
)
print(result)
📘 API
ThreadUtils.run_parameterized_task(
task,
params,
*,
mode="auto", # auto | cpu | io | thread | process
max_workers=None,
thread_name_prefix="default",
timeout=None,
timeout_total=None,
ordered=True,
result_order=None, # "input" | "completed"
chunksize=1, # meaningful for process + ordered=True
max_tasks=None,
return_exceptions=False,
stats=None, # RunStats
)
🧭 Mode selection
auto/cpu: use thread pool on free-threaded runtimes, otherwise process poolio/thread: always use a thread poolprocess: always use a process pool
📝 Behavior notes
- Process pools require
taskto be a top-level function and parameters to be pickle-able. - With
ordered=True, process pool usesmap; per-item timeout is not available in this path. - With
ordered=False, results are returned by completion order. - For ordered process pools, enabling timeout/return_exceptions/timeout_total switches to
submitand ignoreschunksize. timeout_totalenforces a total runtime limit; it may raiseTimeoutError.- When
return_exceptions=True, exceptions are returned in the result list.
🧱 Project structure
smartpool/
├── __init__.py
├── thread.py
└── py.typed
📄 License
MIT License. See LICENSE 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 smartpool_core-0.1.0.tar.gz.
File metadata
- Download URL: smartpool_core-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67664c41b79037eeeabceffa92d80867bfd11f5a2a2a6c4bccb3cd6b4c2dbfca
|
|
| MD5 |
c86474808a1c83c04f46e7be530320ce
|
|
| BLAKE2b-256 |
5465a153e52ba2fc6deccb4d39be962a55ea0b06f7633a5ce29fd30f1d1853f4
|
File details
Details for the file smartpool_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: smartpool_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24d66b8a6be1a9588eed43e791c2e17a1b2268424d8627e3166dbb64cfd405a4
|
|
| MD5 |
44fcbc95f5b21cb5e322754b8ae17d66
|
|
| BLAKE2b-256 |
1b621afd5e7835311eb97d9c5dd7bfac7313619a287f6dcc8b3d5df1049f4fe4
|