本文介绍了python psutil psutil.get_process_list()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试使用python psutil做一些事情,但遇到一个奇怪的错误.

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

procs = psutil.get_process_list()

给我以下错误:

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

我唯一发现的是: 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?

提前谢谢!

推荐答案

在查看文档后此处,我在psutil中没有看到get_process_list()函数,它已根据.

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

也许您应该尝试使用该功能-process_iter()-文档此处

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

它产生一个迭代器,该迭代器将系统中的所有进程作为Process类对象返回.

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

然后,您可以使用list(..)将它们转换为列表(如果列表是您真正想要的),或者,如果您只想对它们进行迭代(如果您只是想对它们进行迭代),则可以直接在for循环中使用迭代器.一步一步地遍历它们,转换为列表将是不必要的开销.

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).

示例-

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

或者如果您想要列表-

procs = list(psutil.process_iter())

这篇关于python psutil psutil.get_process_list()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:51