So the thing is I want to get the return value from the starmap_async. However if I use the .get() to get the list of the result, it is little slow and same as starmap. How do I change the following sample code?
full_res = []
def return_result(result):
full_res.append(result)
with mp.get_context("spawn").Pool(5,maxtasksperchild=1000) as pool:
result=pool.starmap_async(fun, [(args)],callback=return_result)
pool.close()
pool.join()
By the way, I do not need the order.
If you don't care about the order of results and you want to get results as they become available, consider using the
concurrent.futuresmodule instead:Run this code, and you will see that results are displayed as soon as they become available. There is a
mapmethod available that may be appropriate depending on the nature of your work function; we could rewrite the above like: