Skip to main content

AIOPools is a lightweight library for building Python AsyncIO coroutine pools. | AIOPools 是一个轻量级的用于构建 Python AsyncIO 协程池的库。

Project description

aiopools

中文版

AIOPools is a Python AsyncIO Semaphore wrapper for building AsyncIO coroutine pools. ThreadPoolExecutor (thread pool) and ProcessPoolExecutor (process pool) similar to concurrent.futures, designed to enable Python code to achieve the highest number of concurrency.

installation method

Environmental requirements: Python 3.8 and above

  1. Enter the command window, create a virtual environment, and enter the following commands in sequence

Linux and macOS:

python3 -m venv venv # Create a virtual environment
.venv/bin/activate # Activate the virtual environment

Windows:

python -m venv venv # Create a virtual environment
venv\Scripts\activate # activate the virtual environment
  1. Install AIOPools, enter in sequence
pip install --upgrade pip
pip install aiopools

Link

Minimal example

'''
     The total number of coroutine tasks in this example is 100. If the maximum allowed number of coroutines maxio is set to 20, it needs to run 5 times to complete.
'''

import asyncio
from aiopools import AsyncPool


async def block_io(i):
     await asyncio. sleep(1)
     print(i)
     return i


async def main():
     # Set the maximum number of coroutines allowed maxio
     async with AsyncPool(maxio=20) as pool:
         tasks = [pool. create_task(block_io(i)) for i in range(100)]
    
     response = await asyncio. gather(*tasks)
     print(response)
    

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

中文版

AIOPools 是 Python AsyncIO Semaphore 的包装器,用于构建 AsyncIO 协程池。类似于 concurrent.futures 的 ThreadPoolExecutor (线程池) 和 ProcessPoolExecutor (进程池),旨在使 Python 代码达到最高并发数。

安装方法

环境要求:Python 3.8 及以上

1.进入命令窗口,创建虚拟环境,依次输入以下命令

Linux 和 macOS:

python3 -m venv venv # 创建虚拟环境
. venv/bin/activate # 激活虚拟环境

Windows:

python -m venv venv # 创建虚拟环境
venv\Scripts\activate # 激活虚拟环境

2.安装 AIOPools,依次输入

pip install --upgrade pip
pip install aiopools

链接

最简示例

'''
    该示例的协程任务数总计 100 个,设置最大允许的协程数 maxio 为 20,则需要运行 5 次才能完成。
'''

import asyncio
from aiopools import AsyncPool


async def block_io(i):
    await asyncio.sleep(1)
    print(i)
    return i


async def main():
    # 设置最大允许的协程数 maxio
    async with AsyncPool(maxio=20) as pool:
        tasks = [pool.create_task(block_io(i)) for i in range(100)]
    
    response = await asyncio.gather(*tasks)
    print(response)
    

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

AIOPools-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

AIOPools-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file AIOPools-0.1.0.tar.gz.

File metadata

  • Download URL: AIOPools-0.1.0.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

Hashes for AIOPools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a1dec2eb1594fdc98680cedd9f9d94d9724c331c056d7daec2111c969443c08e
MD5 ebf28525dfeee1a20a28d2f57428a1a0
BLAKE2b-256 2c62e93d80eb5e77841bc8fadb56492507898ee6d113375039a4cba47f2b93e4

See more details on using hashes here.

File details

Details for the file AIOPools-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: AIOPools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for AIOPools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1edebbfc37f0d3e544b240fab1db45a8f91ab2c94daf74ecc27252f708fa7d4a
MD5 2d1714d87658b974e5ad416c63057d12
BLAKE2b-256 9b2e9d5b5a2c4985058c2b6fe16535894ebd88a52238fe85b4bead14ac776794

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page