python map_async code example
Example 1: python async map
import paco
async def mul_2(num):
return num * 2
await paco.map(mul_2, [1, 2, 3, 4, 5])
# => [2, 4, 6, 8, 10]
Example 2: worker pool model with multiprocessing
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))