Skip to main content

smartpool

Auto-selecting thread/process pool utilities for parameterized tasks.

English | 简体中文

Python Typing License

✨ 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
  • auto mode 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 pool
  • io / thread: always use a thread pool
  • process: always use a process pool

📝 Behavior notes

  • Process pools require task to be a top-level function and parameters to be pickle-able.
  • With ordered=True, process pool uses map; 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 submit and ignores chunksize.
  • timeout_total enforces a total runtime limit; it may raise TimeoutError.
  • 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.

Metadata

Release files for smartpool-core 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smartpool-core 0.1.0
File Size Uploaded Provenance Actions
smartpool_core-0.1.0.tar.gz 9.1 kB Without provenance Details for smartpool_core-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smartpool-core 0.1.0
File Interpreter ABI Platform Actions
smartpool_core-0.1.0-py3-none-any.whl Python 3 none any Details for smartpool_core-0.1.0-py3-none-any.whl

Total release size: 15.7 kB

Release files / smartpool_core-0.1.0.tar.gz

Download URL smartpool_core-0.1.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
67664c41b79037eeeabceffa92d80867bfd11f5a2a2a6c4bccb3cd6b4c2dbfca
BLAKE2b-256 checksum
How to use checksums
5465a153e52ba2fc6deccb4d39be962a55ea0b06f7633a5ce29fd30f1d1853f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.13

Release files / smartpool_core-0.1.0-py3-none-any.whl

Download URL smartpool_core-0.1.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24d66b8a6be1a9588eed43e791c2e17a1b2268424d8627e3166dbb64cfd405a4
BLAKE2b-256 checksum
How to use checksums
1b621afd5e7835311eb97d9c5dd7bfac7313619a287f6dcc8b3d5df1049f4fe4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.13

Security for smartpool-core 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page