I am writing a benchmarking utility using python. I would like my python program to execute a program and capture the output as well as get its max resource usage. The following code runs a command and gets its memory and processor usage once per second, but how do I also access the output inside python? Here is my current setup:
pid = psutil.Popen(cmd_args, shell=False, stdout=subprocess.PIPE)
p = psutil.Process(pid=pid.pid)
x = 0
cpu_util = []
mem_util = []
while p.status() != "zombie":
if x % 10 == 0:
with p.oneshot():
cpu_util.append(p.cpu_percent())
mem_util.append(p.memory_percent())
x += 1
time.sleep(0.1)
max_cpu_load = max(cpu_util)
max_mem_load = max(mem_util)
#What I would like to do, but don't understand
print(pid.stdout)