python3 使用 multiprocessing.Pool时,子进程未启动
天蓬老师
天蓬老师 2017-04-17 16:58:10
0
2
509
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
刘奇

Just add p.join() after A code p.close() and it will be equivalent. p.close() 之后加一句 p.join() 就是等效的。

或者在 B 代码 p_fi.start() 之前加一句 p_fi.daemon = p_se.daemon = p_th.daemon = True

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. 🎜
刘奇

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template