Skip to main content

Flexexecutor

Testing Package version Python

Flexexecutor provides executors that can automatically scale the number of workers up and down.

Overview

Flexexecutor implements several subclasses of concurrent.futures.Executor. Like the built-in ThreadPoolExecutor and ProcessPoolExecutor, they create multiple workers to execute tasks concurrently. Additionally, it can shut down idle workers to save resources. These subclasses are:

  • ThreadPoolExecutor - thread concurrency, same name as the built-in class and can be a in-place replacement.
  • AsyncPoolExecutor - coroutine concurrency. Note that in flexexecutor's implementation, all coroutines are executed in a dedicated worker thread.
  • ProcessPoolExecutor - flexexecutor directly imports the built-in implementation as it already has scaling capabilities.

Features

  • Supports various concurrency modes: threads, processes and coroutines.
  • Automatically shut down idle workers to save resources.
  • Single file design, keeps the code clean and easy for hackers to directly take away and add more features.

Installation

Flexexecutor is available on PyPI:

pip install flexexecutor

Usage

ThreadPoolExecutor

from flexexecutor import ThreadPoolExecutor


def task(i):
    import time

    print(f"task {i} started")
    time.sleep(1)

if __name__ == "__main__":
    with ThreadPoolExecutor(
        # 1024 is the default value of max_workers, since workers are closed if they are
        # idle for some time, you can set it to a big value to get better short-term
        # performance.
        max_workers=1024,
        # Timeout for idle workers.
        idle_timeout=60.0,
        # These parameters are given for compatibility with the built-in
        # `ThreadPoolExecutor`, I don't use them very often, do you?
        thread_name_prefix="Task",
        initializer=None,
        initargs=(),
    ) as executor:
        for i in range(1024):
            executor.submit(task, i)

AsyncPoolExecutor

AsyncPoolExecutor runs all coroutines in a dedicated worker thread with its own event loop. Note that tasks are not executed in the thread where they are submitted — they are sent to the internal worker thread for execution.

from flexexecutor import AsyncPoolExecutor


async def task(i):
    import asyncio

    print(f"task {i} started")
    await asyncio.sleep(1)

if __name__ == "__main__":
    # AsyncPoolExecutor behaves just like ThreadPoolExecutor except it only accepts
    # coroutine functions.
    with AsyncPoolExecutor(
        # Default value of max_workers is huge, if you don't like it, set it smaller.
        max_workers=1024,
        # Idle timeout for the working thread.
        idle_timeout=60.0,
        # These parameters are given for compatibility with the built-in
        # `ThreadPoolExecutor`, I don't use them very often, do you?
        thread_name_prefix="Task",
        initializer=None,
        initargs=(),
    ) as executor:
        for i in range(1024):
            executor.submit(task, i)

ProcessPoolExecutor

ProcessPoolExecutor in flexexecutor is just the same as the built-in concurrent.futures.ProcessPoolExecutor, we just import it directly for convenience.

Metadata

Release files for flexexecutor 0.0.13

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

Source distribution (sdist)

Source distribution for flexexecutor 0.0.13
File Size Uploaded Provenance
flexexecutor-0.0.13.tar.gz 9.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for flexexecutor 0.0.13
File Interpreter ABI Platform
flexexecutor-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / flexexecutor-0.0.13.tar.gz

Download URL flexexecutor-0.0.13.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
469bafbc107416ef65e5b50452415573fbcca1254f2df92deb25caebf6142978
BLAKE2b-256 checksum
How to use checksums
456fe1b42be84c1de90c859bc937d45116587dacba7ba64b66848da291552475
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.29.3 CPython/3.14.8 Linux/6.17.0-1022-azure

Release files / flexexecutor-0.0.13-py3-none-any.whl

Download URL flexexecutor-0.0.13-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a66edb465b124d2b7a46649b0f2db79bb1603f10e82371bb514da164773ac9f
BLAKE2b-256 checksum
How to use checksums
e2f89b9b38f6a40a06d90989c6ad1d687074be6c3ff1c74400444bccab7a03f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via pdm/2.29.3 CPython/3.14.8 Linux/6.17.0-1022-azure

Security for flexexecutor 0.0.13

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.

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