调试挂起多处理脚本

2024-05-20 17:59:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个脚本,它接收一些数据并将其添加到数据库,以及将图像下载到磁盘上,该脚本通过35个multiprocess.Pool进程调用ingest_item()函数。在

我在整个脚本中有很多日志记录,但是在运行了大约1-1.5天之后(它有很多要接收的),Jenkins作业上的日志输出将停止并挂起,脚本将不再接收数据。在

我尝试添加更多日志来确定问题的确切位置,但似乎每次都会在不同的点停止。在

有人知道我可以让调试更容易吗?在

旁注:我认为问题不在于硬件资源,因为服务器有64gb的RAM。在

def run_ingest_item(*args, **kwargs):
    try:
        ingest_item(*args, skip_recent=True, **kwargs)
    except Exception:
        exec_info = ''.join(traceback.format_exception(*sys.exc_info()))
        logger.error(
            'Failed to ingest item: %s, Exception raised: \n %s',
            args, exec_info
        )


if __name__ == '__main__':
    pool = Pool(35)
    item_ids = get_ids_to_ingest()
    pool.map(run_ingest_item, item_ids)

Tags: to数据runinfo脚本数据库idsexception