I'm trying to implement asynchronous multiprocessing programming with callbacks in python. I read materials about multiprocessing module, process/thread pool and asyncio module but could not get to point. I have a corutine and a callback function like
async def func(x):
value = await (other coroutine)
return x
def callback(x):
print(x)
and I want to submit func(1), func(2), func(3), ... , func(100) to a pool of worker processes of given number, say, 5 processes. Then I want to makes those workers to invoke the callback whenever any of the return values arrives the parent process, not after every return value arrives the parent process.
map/map_async/starmap/starmap_async methods in multiprocessing.Pool waits all of the returns from the worker processes arrives the parent process. I studied basic elements of asynchronous programming in asyncio module in python, but it still remains elusive for me to accomplish the above task - asynchronous multiprocessing programming with callbacks
Could anybody give me a lucid example code for this task?
Thanks in advance.