so i just wrote a simple code with multiprocessing,Pool() and Queue() and when i execute it with this command it keeps open for ever
python3 m.py i can see that 5 of my Cpu cores finish the job and cpu usage decrease to normal but steel its not closing and i have to press Ctrl + c to exit from it.
here is my code :
from multiprocessing import Queue,Pool import csv,json from itertools import chain def worker(line): j_string = json.dumps(line) worker.output_q.put(j_string) def worker_init(output_q): worker.output_q = output_q f_open = open('khodro','rt') f_csv = csv.reader(f_open) output_q = Queue() pool = Pool(5,worker_init,[output_q]) pool.imap(worker,chain(f_csv),1000) raise SystemExit()
if __name__=="__main__"before creating the pool.imapis not blocking and the script you posted generated 5 processes but the parent process immediately terminates and also makes the subprocesses terminate. Either you have ajoin()at the end or you consume the elements byfor el in pool.imap, but the script as you have pasted does not do what you describekhodro?