[英]unable to get process name with psutil
我正在使用它來獲取當前進程。 它確實可以在我的機器上運行,但是當我在另一台機器上運行時卻不能。
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...
我收到這個錯誤
proc_names[p.pid] = p.name()
TypeError: 'str' object is not callable
通過使用p.name,我得到了
for c in psutil.net_connections(kind='inet'):
AttributeError: 'module' object has no attribute 'net_connections'
我猜您的計算機使用的是psutil(2.x)的較新版本,而另一台計算機使用的是1.x的版本。
將p.name()更改為p.name是正確的做法,但我認為1.x中不存在net_connections。 嘗試改用get_connections或在另一台計算機上更新psutil
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.