运行完后,Python脚本占用内存

时间:2019-09-17 17:31:15

标签: python memory memory-management memory-leaks

我有一个很短的python脚本:

import pickle
import pandas as pd

pd.set_option('max_rows', 500)

table_list = ['company', 'partnership', 'reward', 'group']
table_dict = {}

for table in table_list:
    with open(f'pickled_dataframes/{table}_df.pickle', 'rb') as f:
        table_dict[table] = pickle.load(f)
print('Done')

当我运行脚本时,它会出现在Mac的活动监视器中,并占用大量内存(因为我正在加载一些大熊猫数据帧)。但是,当脚本停止运行时,脚本将继续占用此内存。而且,如果我再次运行该脚本,它将出现两次,并且除非我在活动监视器中手动终止该进程,否则任何实例都不会消失。

enter image description here

当我在运行脚本后手动终止该进程时,以下消息将显示在我的崇高文本输出框中:

enter image description here

任何帮助诊断和解决此问题的方法将不胜感激。

0 个答案:

没有答案