A process in the process pool was terminated abruptly while the future was running or pending

ProcessPoolExecutor执行过程中报错

在使用 Python 的 multiprocessing 模块时遇到错误 “A process in the process pool was terminated abruptly while the future was running or pending”,意味着某个子进程在执行任务时发生了异常或被意外终止 。
在多进程处理过程中出现问题的原因可能性多:

    1. 子进程崩溃
      子进程可能因为某些未捕获的异常而崩溃。确保在子进程中捕获并处理所有可能的异常。
    1. 内存不足
      如果子进程占用过多内存,可能会导致操作系统杀死进程。检查每个子进程的内存使用情况,并优化内存使用。
    1. 资源限制
      操作系统可能对进程的数量或资源使用有严格的限制。检查系统的资源限制并适当调整。
    1. 数据传输问题
      在进程间传递大量数据时,可能会导致性能问题或内存溢出。尽量减少数据传输量。
    1. 代码逻辑问题
      确保子进程中的代码逻辑是正确的,特别是涉及到共享资源或并发操作的部分。

为了保证代码能够全量执行完,再通过日志,解决处理并行过程中出现的问题。

1.问题现象

模拟代码:

import multiprocessing
from concurrent.futures import ProcessPoolExecutor, as_completed
import time

str_list= ['a','b','c','d','e','f','g','h','i']
def worker(x):

    # 模拟一些工作
    result = x * x
    time.sleep(1)
    print(str_list[x])
        
    
[/public/home/pengjy/anaconda3] >>> PREFIX=/public/home/pengjy/anaconda3 WARNING: md5sum mismatch of tar archive expected: 8a581514493c9e0a1cbd425bc1c7dd90 got: 614f6284c34f91affd38a1be2e4be076 - Unpacking payload ... Traceback (most recent call last): File "entry_point.py", line 76, in <module> File "tarfile.py", line 2024, in extractall File "tarfile.py", line 2065, in extract File "tarfile.py", line 2137, in _extract_member File "tarfile.py", line 2186, in makefile File "tarfile.py", line 249, in copyfileobj tarfile.ReadError: unexpected end of data [210095] Failed to execute script entry_point concurrent.futures.process._RemoteTraceback: ''' Traceback (most recent call last): File "concurrent/futures/process.py", line 368, in _queue_management_worker File "multiprocessing/connection.py", line 251, in recv TypeError: __init__() missing 1 required positional argument: 'msg' ''' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "entry_point.py", line 69, in <module> File "concurrent/futures/process.py", line 484, in _chain_from_iterable_of_lists File "concurrent/futures/_base.py", line 611, in result_iterator File "concurrent/futures/_base.py", line 439, in result File "concurrent/futures/_base.py", line 388, in __get_result concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending. [210105] Failed to execute script entry_point 是什么问题,如何解决?
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值