flexible_thread_pool ,auto expand thread and reduce threads. both support sync and asyncio,fast than concurrent.futures.ThreadpoolExecutor
Project description
1. flexible_thread_pool
flexible_thread_pool ,auto expand thread and reduce threads. both support sync and asyncio,fast than concurrent.futures.ThreadpoolExecutor
可扩大和自动缩小的线程池,比 threadpool_executor_shrink_able 实现更简单的线程池,性能超过 concurrent.futures.ThreadpoolExecutor 200%
另一个本人实现的可自动扩大和缩小的线程池: https://github.com/ydf0509/threadpool_executor_shrink_able
说明: 此线程池支持submit 方法,但不支持Future特性,只支持简单粗暴的submit自动并发执行。
1.2 flexible_thread_pool 性能说明
在 win11 + r5 4600u 这个很差的cpu 前提下, 单核单进程测试下,每秒执行2万次 def f(): pass 函数。
2. 安装
pip install flexible_thread_pool
3 用法
FlexibleThreadPool 能够支持同步函数和asyncio异步函数的并发执行。
import asyncio
import time
from flexible_thread_pool import FlexibleThreadPool
def testf(x):
time.sleep(10)
if x % 10000 == 0:
print(x)
async def aiotestf(x):
await asyncio.sleep(1)
if x % 10 == 0:
print(x)
return x * 2
pool = FlexibleThreadPool(100)
# pool = ThreadPoolExecutor(100)
for i in range(20000):
# time.sleep(2)
pool.submit(aiotestf, i)
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
File details
Details for the file flexible_thread_pool-0.2.tar.gz
.
File metadata
- Download URL: flexible_thread_pool-0.2.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2683994639ad00f430520b8ae5c5e2d8cccd1e334f5095eed69c38b95e368daf |
|
MD5 | 75523e2453852f216848acdf98a11ef5 |
|
BLAKE2b-256 | ba600140ba236b8a6acef5ad675b5cf39684e5b44205ff8ad0cbd13df08edea7 |