一个异步多进程python包aiomultiprocess
aiomultiprocess是一个异步多进程的python库,其依赖于aiohttp和asyncio两个库。aiohttp是一个基于asyncio的异步http客户端和服务器。asyncio 是用来编写 并发 代码的库,使用 async/await 语法。asyncio 被用作多个提供高性能 Python 异步框架的基础,包括网络和网站服务,数据库连接库,分布式任务队列等等。
On their own, AsyncIO and multiprocessing are useful, but limited: AsyncIO still can’t exceed the speed of GIL, and multiprocessing only works on one task at a time. But together, they can fully realize their true potential.
aiomultiprocess presents a simple interface, while running a full AsyncIO event loop on each child process, enabling levels of concurrency never before seen in a Python application. Each child process can execute multiple coroutines(协程) at once, limited only by the workload and number of cores available.
举个例子:
1 | #coding:utf8 |
asyncio.run
is a Python 3.7 addition. In 3.5-3.6, your example is roughly equivalent to:
1 | import asyncio |