我试图在我的 python 脚本中获取外部程序的内存使用情况。我试过使用脚本 http://code.activestate.com/recipes/286222/如下:
m0 = memory()
subprocess.call('My program')
m1 = memory(m0)
print m1
但这似乎只是给我 python 脚本的内存使用情况,而不是“我的程序”。有没有办法输出程序的内存使用情况,以便在 python 脚本中使用?
最佳答案
尝试使用 Psutil
import psutil
import subprocess
import time
SLICE_IN_SECONDS = 1
p = subprocess.Popen('calling/your/program')
resultTable = []
while p.poll() == None:
resultTable.append(psutil.get_memory_info(p.pid))
time.sleep(SLICE_IN_SECONDS)
关于python - 如何获取外部程序的内存使用情况 - python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12263779/