多处理池星图会导致OS错误:打开了太多文件

问题描述

因此,我正在运行此脚本,该脚本使用多处理池并行运行一个函数。我的代码格式较早:

with mp.pool(n_workers) as pool:
    for i in range(some_iterations):
        for ele in some_list:
            soln = pool.starmap(some_function,some_arguments)
            add_soln_to_json(soln)

但是我进行了更改,必须检查一些条件并额外运行starmap。所以我的代码变成了:

with mp.pool(n_workers) as pool:
    for i in range(some_iterations):
        for ele in some_list:
            soln = pool.starmap(some_function,some_arguments)
            add_soln_to_json(soln)
            if(some_condition):
                soln = pool.starmap(some_function,some_arguments)
                add_soln_to_json(soln)

我的程序现在不断给我操作系统错误:打开的文件太多。我不明白为什么添加一个额外的步骤运行相同的功能,但参数略有不同会导致此错误。同样,由于所有内容都在上下文管理器下,因此不关闭进程也没有问题。还是应该用手动打开和关闭多处理池来代替它?

这是错误回溯:

Traceback (most recent call last):
  File "/share/pkg.7/python3/3.7.7/install/lib/python3.7/multiprocessing/resource_sharer.py",line 149,in _serve
    send(conn,destination_pid)
  File "/share/pkg.7/python3/3.7.7/install/lib/python3.7/multiprocessing/resource_sharer.py",line 50,in send
    reduction.send_handle(conn,new_fd,pid)
  File "/share/pkg.7/python3/3.7.7/install/lib/python3.7/multiprocessing/reduction.py",line 179,in send_handle
    with socket.fromfd(conn.fileno(),socket.AF_UNIX,socket.SOCK_STREAM) as s:
  File "/share/pkg.7/python3/3.7.7/install/lib/python3.7/socket.py",line 463,in fromfd
    nfd = dup(fd)
OSError: [Errno 24] Too many open files

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...