可乐博客

async 多进程小记

import concurrent.futures
import asyncio


def get(x):
    print(x)


async def main():
    p = concurrent.futures.ProcessPoolExecutor()
    for i in range(10):
        obj = p.submit(get, i)
        fut = asyncio.wrap_future(obj)
        # await asyncio.sleep(1)
        await fut

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