python - 如何获取外部程序的内存使用情况 - python

标签 python memory external-process

我试图在我的 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/

相关文章:

java - 如何在eclipse中添加外部jar文件doc?

python - 斐波那契上的 U 组合器 : how would you translate this code to python?

python - 如何从 tensorflow RNN 中选取最后一个有效输出值

memory - 使用什么来查看 Spark 的内存使用情况(使用 YARN)?

python - 计算 numpy memmap Infinity 输出的均值和方差

C# : Redirect console application output : How to flush the output?

python - 如何在 Python 2 中发送 HEAD HTTP 请求?

python - SAP HANA Python 连接 HDBCLI

c++ - Windows Vista+ IFileOpenDialog 和大堆栈的内存问题

c# - 打开没有 Process.start 的网站