A Python 3.5+ library that integrates the multiprocessing module with asyncio.
Likely abandoned. No release or commit for years (last release over 4 years ago).
pip install aioprocessingaioprocessing
aioprocessing provides asynchronous, asyncio compatible, coroutine
versions of many blocking instance methods on objects in the multiprocessing
library. To use dill for universal pickling, install using pip install aioprocessing[dill]. Here's an example demonstrating the aioprocessing versions of
Event, Queue, and Lock:
import time
import asyncio
import aioprocessing
def func(queue, event, lock, items):
""" Demo worker function.
This worker function runs in its own process, and uses
normal blocking calls to aioprocessing objects, exactly
the way you would use oridinary multiprocessing objects.
"""
with lock:
event.set()
for item in items:
time.sleep(3)
queue.put(item+5)
queue.close()
async def example(queue, event, lock):
l = [1,2,3,4,5]
p = aioprocessing.AioProcess(target=func, args=(queue, event, lock, l))
p.start()
while True:
result = await queue.coro_get()
if result is None:
break
print("Got result {}".format(result))
await p.coro_join()
async def example2(queue, event, lock):
await event.coro_wait()
async with lock:
await queue.coro_put(78)
await queue.coro_put(None) # Shut down the worker
if __name__ == "__main__":
loop = asyncio.get_event_loop()
queue = aioprocessing.AioQueue()
lock = aioprocessing.AioLock()
event = aioprocessing.AioEvent()
tasks = [
asyncio.ensure_future(example(queue, event, lock)),
asyncio.ensure_future(example2(queue, event, lock)),
]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
The aioprocessing objects can be used just like their multiprocessing
equivalents - as they are in func above - but they can also be
seamlessly used inside of asyncio coroutines, without ever blocking
the event loop.
What's new
v2.0.1
- Fixed a bug that kept the
AioBarrierandAioEventproxies returned fromAioManagerinstances from working. Thanks to Giorgos Apostolopoulos for the fix.