如何使用aiomultiprocess?

问题描述

我发现这个软件包aiomultiprocess似乎可以同时进行多处理和异步处理。

from aiohttp import request
from aiomultiprocess import Pool


async def get(url):
    async with request("GET",url) as response:
        return await response.text("utf-8")


async def main():
    urls = ["https://jreese.sh","https://www.google.com",]
    async with Pool() as pool:
        async for result in pool.map(get,urls):
            print(result)

但是,尝试运行示例代码绝对没有任何作用。

尝试致电main()给我一个错误RuntimeWarning: coroutine 'main' was never awaited。我找不到如何触发代码的实际示例。

关于此的唯一其他question未得到回答。

解决方法

<Button @attributes="@Attributes" Color="Colors.Primary">文档示例未涵盖如何调用循环。该功能需要通过asyncio调用。

aiomultiprocess