跳转到主要内容

一个在asyncio事件循环中运行异步任务的concurrent.futures.Executor实现。

项目描述

aio-executor

Build Status

一个在asyncio循环中运行异步任务的concurrent.futures.Executor实现。

示例用法

from aio_executor import AioExecutor

async def my_async_function(arg):
    # ...

with AioExecutor() as aioexec:
    # single invocation
    f = aioexec.submit(my_async_function, 'foo')
    result = f.result()

    # multiple concurrent invocations using "map"
    results = aioexec.map(my_async_function, ['foo', 'bar', 'baz'])

为了方便,还提供了一个run_with_asyncio装饰器。这个装饰器在AioExecutor实例中运行装饰的异步函数。

以下示例展示了如何使用此装饰器实现Flask框架的异步视图函数

@app.route('/')
@run_with_asyncio
async def index():
    return await get_random_quote()

如何安装

pip install aio-executor

项目细节


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

aio-executor-0.2.0.tar.gz (2.6 kB 查看哈希值)

上传时间:

构建分布

aio_executor-0.2.0-py2.py3-none-any.whl (3.5 kB 查看哈希值)

上传于 Python 2 Python 3

支持者

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页