我正在使用pupynere接口(linux)读取一堆netcdf文件。以下代码导致 mmap 错误:
import numpy as np
import os, glob
from pupynere import NetCDFFile as nc
alts = []
vals = []
path='coll_mip'
filter='*.nc'
for infile in glob.glob(os.path.join(path, filter)):
curData = nc(infile,'r')
vals.append(curData.variables['O3.MIXING.RATIO'][:])
alts.append(curData.variables['ALTITUDE'][:])
curData.close()
错误:
$ python2.7 /mnt/grid/src/profile/contra.py
Traceback (most recent call last):
File "/mnt/grid/src/profile/contra.py", line 15, in <module>
File "/usr/lib/python2.7/site-packages/pupynere-1.0.13-py2.7.egg/pupynere.py", line 159, in __init__
File "/usr/lib/python2.7/site-packages/pupynere-1.0.13-py2.7.egg/pupynere.py", line 386, in _read
File "/usr/lib/python2.7/site-packages/pupynere-1.0.13-py2.7.egg/pupynere.py", line 446, in _read_var_array
mmap.error: [Errno 24] Too many open files
有趣的是,如果我评论其中一个append
命令(任何一条都可以!)它会起作用!我究竟做错了什么?我正在关闭文件,对吧?这在某种程度上与 python 列表有关。我之前使用了一种不同的、低效的方法(总是复制每个元素)。
PS:ulimit -n
产生 1024,程序在文件号 498 处失败。
可能与,但解决方案对我不起作用:NumPy and memmap: [Errno 24] Too many open files