How to view cpu sweat loading on a separate process using Python?

I tried using psutil.

import psutil PROCNAME = "zoiper" for proc in psutil.process_iter(): if proc.name() == PROCNAME: a=proc.pid p = psutil.Process(a) print(p.status) print(p.cpu_percent()) print(p.cpu_affinity()) 

answer

 <bound method Process.status of <psutil.Process(pid=8129, name='zoiper') at 140221375194168>> 0.0 [0, 1, 2, 3, 4, 5, 6, 7] 

Although the download is there, but it shows 0.0, maybe I'm doing something wrong?

    1 answer 1

    The psutil.Process documentation explicitly says:

    When it’s time for the system, it has been set to 0 times. It means a meaningless 0.0 value of what it is supposed to ignore.

    interval=None by default, so the first return value should be ignored. The second and subsequent calls reflect the values ​​from the last call (the documentation does not recommend calling it more than once every 0.1 seconds).

    Alternatively, it is possible to transfer the interval > 0 to the .cpu_percent() method to get a value for the specified period.

    • Thanks, that is necessary., That with looked through that. - xmaster83