Or adding p_fi.daemon = p_se.daemon = p_th.daemon = True before the B code p_fi.start() is also equivalent (at this time the B code also cannot operate normally).
In short, the difference is that code A ends the main process without waiting for the sub-process to complete, while code B waits for the sub-process to complete before terminating the main process.
After updating the complete code:
dict_init_queue = Queue()
needs to be changed to:
from multiprocessing import Manager
manager = Manager()
dict_init_queue = manager.Queue()
Otherwise the queue cannot be shared between processes. 🎜
Just add
p.join()
after A codep.close()
and it will be equivalent.p.close()
之后加一句p.join()
就是等效的。或者在 B 代码
Or addingp_fi.start()
之前加一句p_fi.daemon = p_se.daemon = p_th.daemon = True
p_fi.daemon = p_se.daemon = p_th.daemon = True
before the B codep_fi.start()
is also equivalent (at this time the B code also cannot operate normally).The person above is right. After closing, there should be a join to wait for the execution to end
I only found out after reading the code of the project https://github.com/shazow/workerpool