Skip to main content

Build Status PyPI PyPI Version

HybridPoolExecutor

HybridPoolExecutor is a parallel executor that supports thead, process and async three operating models at the same time.

Example:

import asyncio
import time
import random

from hybrid_pool_executor import HybridPoolExecutor


def solve(v: int) -> int:
    print(f"You give worker a value {v}")
    time.sleep(random.randint(1, 4))
    print(f"The square of value {v} is {v * v}")
    return v


async def solve_async(v: int) -> int:
    print(f"You give async worker a value {v}")
    await asyncio.sleep(random.randint(1, 4))
    print(f"The square of value {v} is {v * v}")
    return v


async def main():
    pool = HybridPoolExecutor()

    # run in a thread
    future0 = pool.submit(solve, 0)

    # run in a process by setting "_mode" to "process"
    future1 = pool.submit(solve, 1, _mode="process")
    # or you can use a more precise approach: submit_task
    future2 = pool.submit_task(solve, kwargs={"v": 2}, mode="process")

    # run in an async worker
    future3 = pool.submit(solve_async, 3)  # run as a coroutine
    # you can also submit a coroutine
    future4 = pool.submit(solve_async(4))
    # async function/coroutine can be executed in thread/process too
    # run coroutine in a thread
    future5 = pool.submit(solve_async(5), _mode="thread")
    # or in a process
    future6 = pool.submit(solve_async, 6, _mode="process")

    # all futures can be get either synchronously or asynchronously
    await future0  # result from a thread worker
    await future1  # result from a process worker
    future2.result()  # result from a async worker
    # ......


if __name__ == "__main__":
    asyncio.run(main())

Metadata

Release files for hybrid-pool-executor 0.0.4

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

Source distribution (sdist)

Source distribution for hybrid-pool-executor 0.0.4
File Size Uploaded Provenance Actions
hybrid-pool-executor-0.0.4.tar.gz 29.7 kB Without provenance Details for hybrid-pool-executor-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hybrid-pool-executor 0.0.4
File Interpreter ABI Platform Actions
hybrid_pool_executor-0.0.4-py3-none-any.whl Python 3 none any Details for hybrid_pool_executor-0.0.4-py3-none-any.whl

Total release size: 57.5 kB

Release files / hybrid-pool-executor-0.0.4.tar.gz

Download URL hybrid-pool-executor-0.0.4.tar.gz
Size 29.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fd8a6fbe3853fb6cdcce643b2c37ed615c27cb418d803d966edd803b4e2d74fe
BLAKE2b-256 checksum
How to use checksums
0a70469854956fb0b4c19a3f63a1f7a234a935f1c455ead92fad1f0c6e44426a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.12

Release files / hybrid_pool_executor-0.0.4-py3-none-any.whl

Download URL hybrid_pool_executor-0.0.4-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7dbd9aabcaeb7f38f3e0147428e167cddca7c7ed8c73083b15256f5d5fb39e4
BLAKE2b-256 checksum
How to use checksums
62cfb048a3f60d24f4f2ff0c75d5a58e10452c01dfc07f2194cd1c50b736b0c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.12

Security for hybrid-pool-executor 0.0.4

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