使用np.loadtxt(file)后文件仍然打开吗?

问题描述 投票:0回答:1

我有一个 plaix txt 文件,名为

a.txt
。然后我需要很多程序来读取它,所以我使用
multiprocessing
模块来实现它。在每个程序中,我都使用
numpy.loadtxt
来读取
a.txt
。然后我发现,当我打开太多程序时,比如600个,所有程序都被阻塞。我发现程序中有一个lock。在搜索了有关此主题的一些信息后,我猜测在
numpy.loadtxt
之后,文件对象仍在打开,因此其他程序需要等待文件关闭。使用 np.loadtxt(file) 后文件是否仍在打开?我如何知道文件是否正在关闭。

在搜索了有关此主题的一些信息后,我猜测在 numpy.loadtxt 之后,文件对象仍在打开,因此其他程序需要等待文件关闭。使用 np.loadtxt(file) 后文件是否仍在打开?我如何知道文件是否正在关闭。

python linux numpy file
1个回答
0
投票

numpy.loadtxt() 不会留下打开的(悬空的)文件描述符。

证明:

import numpy as np
import psutil

print(psutil.Process().open_files())
np.loadtxt("foo.txt")
print(psutil.Process().open_files())

输出:

[]
[]
© www.soinside.com 2019 - 2024. All rights reserved.