gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 07:10:43 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com