python - PBS vmem 超出限制:我怎么知道内存超出了哪里?
问题描述
我有一个包含 1500000 个多边形的 shapefile,我需要转到每个多边形并将其与不同的网格相交。
我创建了一个简单的程序,从多边形到多边形的交叉点(使用多处理),
pool = mp.Pool()
for index,pol in shapefile.iterrows():
# Limits each polygon in shapefile
ylat = lat_gridlimits
xlon= lon_gridlimits
args.append((dgrid,ylat,xlon,pol,index))
pool.starmap(calculate,args)
pool.close()
pool.join()
但是内存很快就会填满,我得到一个错误
PBS:作业终止:vmem 超出限制
我如何知道内存超出的位置或时间?或者有没有办法控制每个函数中的内存?
我试过这个(内部计算):
process = psutil.Process(os.getpid())
mem=process.memory_info().rss/(1024.0 ** 3)
vmem=psutil.virtual_memory().total / (1024.0 ** 3)
print("{} {}\n".format(mem,vmem))
但这并不能帮助我找到在哪里
解决方案
内存不足的一个原因可能是因为您在 for 循环中使用迭代器来迭代非常大的数据集。迭代这个集合可能需要比 python 程序允许在你的系统上使用更多的内存。节省内存的一种方法是将作为迭代器的 shapefile.iterrows() 重写为返回生成器的函数,因为生成器计算需要读取的新索引,而不是存储所有索引。
要阅读有关生成器的更多信息,请访问以下链接:
推荐阅读
- php - 如果订单商品属于特定产品类别,则结帐重定向后的 Woocommerce
- java - 未使用 startService 调用 onStartCommand
- git - github历史生成时间太长
- python - 使用python从excel表格中提取颜色
- sql-server - TSQL-JOIN:在联接中将一个表中不存在的值显示为零
- reactjs - 将事件转换为 Redux 操作
- javascript - 反应语义ui,切换选项卡时如何重新渲染组件?
- php - 如何在字符串中包含零?
- php - 如何使用连接表在 Codeigniter 中进行分页?(CI_DB_mysqli_result 类的对象无法转换为字符串)
- c++ - 薄板样条形状变换运行时错误 [退出,代码 -1073741819]