在Jupyter笔记本上的Python进行多处理任务后,如何释放RAM



我在Jupyter笔记本上使用Python中的多处理。我能够使用工人池并行化代码。我面临着记忆交易的问题。

import multiprocessing
def forSources(n):
   temp_pairings = []
   temp_pairings += dfs_edges2(digraph, flights[n[0]], n[1])
   print(multiprocessing.current_process().name, len(temp_pairings))
   return (temp_pairings)
for depth in range(0, 2):
   pool = multiprocessing.Pool()
   result = pool.map(forSources, [[i, depth] for i in range(0, 3000)])
   for pairings in result:
      final_result += pairings
   if len(final_result) > 5000:
      break
   pool.terminate()
   pool.join()

提取final_result后,我想在过程终止后立即释放RAM。例如:此运行大约需要3.5 GB的RAM,并且运行完成后,系统监视器仍显示额外的3.5 GB。我尝试删除形成的所有变量,即使关闭jupyter笔记本也无法解决问题。

尝试存储所有产卵过程的过程ID,完成后杀死所有过程。

最新更新