python3多进程偶尔会有无法停下的bug,因为多进程竞争读取队列时会有Empty exception
所以最好的办法是人为设置进程控制信息,避免因为竞争导致读取队列为空的问题。
[Python,SQL,ETL]交流群 164142295
以下代码完美处理了这个问题
import time
from multiprocessing import cpu_count, Queue, Process
from queue import Empty
import traceback
def add(q, index, Q,waste):
r,b = 0,0
while 1:
try:
args = q.get(block=False)
if args[0] == 1:
Q.put(r)
break
else:
r += 1
except Empty:
b+=1
time.