multiprocessing - Python Multiprocesing async running process one after the other -
import multiprocessing import requests def work(number): link = 'http://apilink/' response = requests.get(link).text print response if __name__ == "__main__": number_processes = 2 pool = multiprocessing.pool(number_processes) results = pool.map_async(work, range(1,3)) pool.close() pool.join()
im running above code run multiprocessing using async 2 process. when run code, running serially not parallely. how run both processes @ time parallely.
you need pool of workers, check out: the docs: using pool of workers
check out docs:
from multiprocessing import pool p = pool(5) def f(x): return x*x p.map(f, [1,2,3])
you need map function list of workers.
be careful demon processes in background.
Comments
Post a Comment