flexible-thread-pool


Nameflexible-thread-pool JSON
Version 0.2 PyPI version JSON
download
home_pagehttps://github.com/ydf0509/flexible_thread_pool
Summaryflexible_thread_pool ,auto expand thread and reduce threads. both support sync and asyncio,fast than concurrent.futures.ThreadpoolExecutor
upload_time2023-08-04 14:24:33
maintainerydf
docs_urlNone
authorbfzs
requires_python
licenseBSD License
keywords thread pool async asyncio auto scala flexible_thread_pool
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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异步函数的并发执行。

```python
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)
```




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ydf0509/flexible_thread_pool",
    "name": "flexible-thread-pool",
    "maintainer": "ydf",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "ydf0509@sohu.com",
    "keywords": "thread pool,async,asyncio,auto scala,flexible_thread_pool",
    "author": "bfzs",
    "author_email": "ydf0509@sohu.com",
    "download_url": "https://files.pythonhosted.org/packages/ba/60/0140ba236b8a6acef5ad675b5cf39684e5b44205ff8ad0cbd13df08edea7/flexible_thread_pool-0.2.tar.gz",
    "platform": "all",
    "description": "# 1. flexible_thread_pool\r\n\r\nflexible_thread_pool \uff0cauto expand thread and reduce threads. both support sync and asyncio,fast than concurrent.futures.ThreadpoolExecutor\r\n\r\n\u53ef\u6269\u5927\u548c\u81ea\u52a8\u7f29\u5c0f\u7684\u7ebf\u7a0b\u6c60\uff0c\u6bd4 threadpool_executor_shrink_able \u5b9e\u73b0\u66f4\u7b80\u5355\u7684\u7ebf\u7a0b\u6c60\uff0c\u6027\u80fd\u8d85\u8fc7 concurrent.futures.ThreadpoolExecutor 200%\r\n\r\n\u53e6\u4e00\u4e2a\u672c\u4eba\u5b9e\u73b0\u7684\u53ef\u81ea\u52a8\u6269\u5927\u548c\u7f29\u5c0f\u7684\u7ebf\u7a0b\u6c60\uff1a https://github.com/ydf0509/threadpool_executor_shrink_able\r\n\r\n\r\n\u8bf4\u660e\uff1a\r\n\u6b64\u7ebf\u7a0b\u6c60\u652f\u6301submit \u65b9\u6cd5\uff0c\u4f46\u4e0d\u652f\u6301Future\u7279\u6027\uff0c\u53ea\u652f\u6301\u7b80\u5355\u7c97\u66b4\u7684submit\u81ea\u52a8\u5e76\u53d1\u6267\u884c\u3002\r\n\r\n## 1.2 flexible_thread_pool \u6027\u80fd\u8bf4\u660e\r\n\r\n\u5728 win11 + r5 4600u \u8fd9\u4e2a\u5f88\u5dee\u7684cpu \u524d\u63d0\u4e0b\uff0c \u5355\u6838\u5355\u8fdb\u7a0b\u6d4b\u8bd5\u4e0b\uff0c\u6bcf\u79d2\u6267\u884c2\u4e07\u6b21 def f(): pass    \u51fd\u6570\u3002\r\n\r\n\r\n# 2. \u5b89\u88c5\r\npip install flexible_thread_pool\r\n\r\n\r\n# 3 \u7528\u6cd5\r\n\r\nFlexibleThreadPool \u80fd\u591f\u652f\u6301\u540c\u6b65\u51fd\u6570\u548casyncio\u5f02\u6b65\u51fd\u6570\u7684\u5e76\u53d1\u6267\u884c\u3002\r\n\r\n```python\r\nimport asyncio\r\nimport time\r\nfrom flexible_thread_pool import FlexibleThreadPool\r\n\r\n\r\ndef testf(x):\r\n    time.sleep(10)\r\n    if x % 10000 == 0:\r\n        print(x)\r\n\r\n\r\nasync def aiotestf(x):\r\n    await asyncio.sleep(1)\r\n    if x % 10 == 0:\r\n        print(x)\r\n    return x * 2\r\n\r\n\r\npool = FlexibleThreadPool(100)\r\n# pool = ThreadPoolExecutor(100)\r\n\r\nfor i in range(20000):\r\n    # time.sleep(2)\r\n    pool.submit(aiotestf, i)\r\n```\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "BSD License",
    "summary": "flexible_thread_pool \uff0cauto expand thread and reduce threads. both support sync and asyncio,fast than concurrent.futures.ThreadpoolExecutor",
    "version": "0.2",
    "project_urls": {
        "Homepage": "https://github.com/ydf0509/flexible_thread_pool"
    },
    "split_keywords": [
        "thread pool",
        "async",
        "asyncio",
        "auto scala",
        "flexible_thread_pool"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba600140ba236b8a6acef5ad675b5cf39684e5b44205ff8ad0cbd13df08edea7",
                "md5": "75523e2453852f216848acdf98a11ef5",
                "sha256": "2683994639ad00f430520b8ae5c5e2d8cccd1e334f5095eed69c38b95e368daf"
            },
            "downloads": -1,
            "filename": "flexible_thread_pool-0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "75523e2453852f216848acdf98a11ef5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3810,
            "upload_time": "2023-08-04T14:24:33",
            "upload_time_iso_8601": "2023-08-04T14:24:33.576443Z",
            "url": "https://files.pythonhosted.org/packages/ba/60/0140ba236b8a6acef5ad675b5cf39684e5b44205ff8ad0cbd13df08edea7/flexible_thread_pool-0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-04 14:24:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ydf0509",
    "github_project": "flexible_thread_pool",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flexible-thread-pool"
}
        
Elapsed time: 0.10139s