Python 多处理池 OSError:打开的文件太多 [英] Python multiprocessing pool OSError: Too many files open

查看:68
本文介绍了Python 多处理池 OSError:打开的文件太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须检查 do_something() 为一对包含 30k 元素的列表总共花费多少时间.下面是我的代码

I have to check how much time do_something() takes in total for a pair of lists containing 30k elements. Below is my code

def run(a, b, data):
    p = datetime.datetime.now()
    val = do_something(a, b, data[0], data[1])
    q = datetime.datetime.now()
    res = (q - p).microseconds
    return res 

接下来,我使用以下代码调用它:

Next, I call this using the following code:

func = functools.partial(run, a, b)

x = np.linspace(500, 1000, 30000).tolist()
y = np.linspace(20, 500, 30000).tolist()

data = zip(x, y)

with multiprocessing.Pool(processes=multiprocessing.cpu_count()) as pool:
    d = pool.map(func, data)
res = sum(d)

每当我运行它时,我总是收到 OSError: [Errno 24] 太多打开的文件.我该如何解决这个问题?

Whenever I run this, I keep getting OSError: [Errno 24] Too many open files. How do I fix this?

推荐答案

您可以使用 ulimit -u 2048 来提高进程限制.

You can use ulimit -u 2048 to raise the process limit.

使用 ulimit -a 检查当前限制.

Use ulimit -a to check the current limits.

这篇关于Python 多处理池 OSError:打开的文件太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆