Repository navigation
|
Hi, I am using psutil in python 2.7 to get the cpu percent of the process, however, it always get 0.0 for current process. The system cpu percent is correct, and the cpu_time per process is also increased. here is the test code which I am using: Here is the output of the test code: Can anybody help to check where's the problem? thank you. Best Regards, |
Replies: 4 comments
|
Try this: |
|
Is it possible to write a async function to get all cpu_percent for all processes returned by |
I guess I found it : list_proc = []
for proc in psutil.process_iter():
list_proc.append(proc)
tasks = []
for i in range(len(list_proc):
tasks.append(asyncio.create_task(update_process_cpu_percent(i, list_proc)))
await asyncio.gather(*tasks)
async def update_process_cpu_percent(index, lst):
percent = lst[index].cpu_percent()
await asyncio.sleep(1)
percent = lst[index].cpu_percent()
# process return as you want
return percent |
|
Try this: