我正在尝试使用以下方法将一些 2 000 FITS 加载到内存中astropy.io.fits
:
def readfits(filename):
with fits.open(filename) as ft:
# the fits contain a single HDU
data = ft[0].data
return data
data_sci = []
for i in range(2000):
data_sci.append(readfits("filename_{}.fits".format(i)))
但是,当达到第 1015 个文件时,OSError: [Errno 24] Too many open
files
会引发。
我有同样的问题:
def readfits(filename):
ft = fits.open(filename) as ft:
data = ft[0].data
ft.close()
return data
我怀疑astropy.io.fits
没有正确关闭文件。有没有办法强制关闭文件?