python psutil psutil.get_process_list() error

拥有回忆 提交于 2019-12-07 03:18:24

问题


Im trying to do some things with python psutil but get a strange error.

procs = psutil.get_process_list()

Gets me the following error:

AttributeError: 'module' object has no attribute 'get_process_list'

The only thing i found about it was this: https://github.com/giampaolo/psutil/issues/524

But no real solution besides pasting it to another directory (which I tried but is not working for me). Does anyone has a clue why I get this error?

Great thanx in advance!


回答1:


After checking the documentation here , I do not see a get_process_list() function in psutil, it has been deprecated according to this .

Maybe you should try the function - process_iter() - documentation here

It yields an iterator that would return all the processes in the system as Process class objects.

You can then use list(..) to convert them to a list (If list is what you really want) , or directly use the iterator in a for loop, if you just want to iterate over them (If you just want to iterate over them one by one, converting to list would be an unnecessary overhead).

Example -

for proc in psutil.process_iter():
    <do your logic>

Or if you want the list -

procs = list(psutil.process_iter())



回答2:


According to HISTORY.rst,

#273: psutil.get_process_list() is deprecated.

Use psutil.process_iter() instead:

procs = list(psutil.process_iter())


来源:https://stackoverflow.com/questions/31216835/python-psutil-psutil-get-process-list-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!