Why do I keep getting [BrokenPipeError: [Errno 32] Broken pipe] no matter the number of workers in my Pool with multiprocessing lib in python3.8?

Why do I keep getting [BrokenPipeError: [Errno 32] Broken pipe] no matter the number of workers in my Pool with multiprocessing lib in python3.8?

我正在尝试使用工作池 python3 的多处理库来加速 CPU 密集型任务。我注意到无论池中有多少工作人员,我总是会收到以下错误:

BrokenPipeError: [Errno 32] Broken pipe

导致此错误的代码如下:


def save_result(rincL):
    #Save results here

if __name__ == '__main__':
    p = Pool(8)
    allProcesses = []
    for i in range(60): 
        rincL = RINC_L(2, X_train, y_train[:,i].ravel(), X_test, y_test[:,i].ravel(), 6, i)
        allProcesses.append(p.apply_async(rincL.RINC_N, [0]))
    #Moved the two following lines based on suggestions in the comment
    #Still getting the same error.
    #p.close()
    #p.join()
    for process in allProcesses:
        save_result(process.get())
        time.sleep(1)
    p.close()
    p.join()

我也注意到这个程序一段时间后 运行。进程数从 8 跳到一个非常高的数字。产生了大约 30 个进程:

子进程使用了​​过多的内存并被 OS 杀死。