简体   繁体   中英

unable to get process name with psutil

I'm using this to get the current processes. It does work on my machine, but it doesn't when I run it on another one.

for p in psutil.process_iter():
    try:
        proc_names[p.pid] = p.name()
    except psutil.Error:
        pass
for c in psutil.net_connections(kind='inet'):
# etc...

I'm getting this error

    proc_names[p.pid] = p.name()
TypeError: 'str' object is not callable

by using p.name, instead I get this

    for c in psutil.net_connections(kind='inet'):
AttributeError: 'module' object has no attribute 'net_connections'

I'm guessing your machine is using a newer of version of psutil (2.x) and the other machine is using a 1.x version.

Changing the p.name() to p.name was the right move, but I don't think net_connections exist in 1.x. Try get_connections instead or update psutil on the other machine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM