4

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
lia1000
  • 159
  • 1
  • 4
  • 13
  • This is not really a question. You should just try to print out the process names and see what's happening. If it's a bug, report it to psutil bug tracker. If there's something you can't explain, ask on the psutil list. In this case, I think the process name is something like `C:\Python27\python.exe` (or something similar). – Noufal Ibrahim Jun 02 '14 at 10:03

3 Answers3

6

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

Joules
  • 540
  • 4
  • 14
  • 1
    thank you, instead of documentation, that how it is really works. Because `name` returns object, and `_name` is filled with delay, and usually has state `None`. And just `name()` acts as expected. – Arkady Dec 08 '15 at 09:27
3

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.

romor
  • 1,181
  • 15
  • 22
-1

Try to see exactly which is the format of the process name served by psutil:

import psutil

for proc in psutil.process_iter():
    print proc.name
user1202136
  • 11,171
  • 4
  • 41
  • 62