Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psutil - getting process name is blank

Tags:

python

psutil

I'm trying to run this code and I'm not getting the list of processes by name:

import psutil

PROCNAME = "python.exe"

for proc in psutil.process_iter():
    if proc.name == PROCNAME:
        print proc

What I get is nothing even though the process is running.

like image 831
lia1000 Avatar asked Mar 20 '23 10:03

lia1000


2 Answers

I was experiencing the same problem. Changing proc.name to proc.name() solved it for me if anyone else was having similar issues.

like image 94
Joules Avatar answered Mar 21 '23 23:03

Joules


There have been significant changes in the psutil API with version 2.0.0:

https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#200---2014-03-10

The proc.name class property was replaced by the proc.name() method. So you need to adapt this.

like image 39
romor Avatar answered Mar 21 '23 23:03

romor