Search code examples
pythonpsutil

Not able to use psutil.Process()


For the following code, I get the error, str not callable. Also I am not able to access any of the functions within the class. When I copy-paste examples straight from the docs, I still get the error.

import psutil
p = psutil.Process(4011)
p.name()

Solution

  • You have to use p.name instead of p.name() when using psutil in version 1.2.1. In version 2.X you can use p.name() (https://pythonhosted.org/psutil/#psutil.Process.name).

    >>> p=psutil.Process(21443)
    >>> p.name
    'kworker/0:1'
    >>> p.name()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'str' object is not callable