Python process load request

Is there any portable way for a Python process to request a load on its CPU?

If the ps command exists, I can run it and analyze the results, but this is less desirable.

+3
source share
2 answers

you can use psutil :

import os
import psutil

pid = os.getpid()
p = psutil.Process(pid)
pct = p.get_cpu_percent(interval=1.0)
print(pct)
+3
source

Guppy / Heapy may be useful to you, but there are version problems, and it may not do everything you need.

0
source

All Articles