Skip to content Skip to sidebar Skip to footer

Cross-platform Resource Usage On Subprocess.popen

First of all if this has been asked before I'm sorry for the duplicate, but I couldn't find the answer to my question anywhere. So, I am pretty new to Python, and I am currently wo

Solution 1:

psutil provides a cross-platform solution to get resource usage of a subprocess e.g.:

import random
import psutil # $ pip install psutil

p = psutil.Process(random.choice(psutil.pids()))
print(p.name())
print(p.cpu_times())
print(p.memory_info())

to get the info for an existing subprocess.Popen instance just pass popen_instance.pid to psutil.Process. You could also create a subprocess using psutil.Popen directly.

Post a Comment for "Cross-platform Resource Usage On Subprocess.popen"