Python 中的 WMI 查询问题
我最近一直在编写 Squish 测试脚本,并尝试执行类似于解决方案中描述的操作: Python进程使用的总内存?
我的代码中的相关片段如下:
def measureMemory():
w = wmi.WMI('.')
result = w.query("SELECT WorkingSet FROM Win32_PerfRawData_PerfProc_Process WHERE Name=\"some_program\"")
print result
for WorkingSet in result:
print WorkingSet
subset = result[0]
print subset['WorkingSet']
# return result[0]['WorkingSet']
for i in range(50):
memory = measureMemory()
if memory:
# test.passes("%d memory used during undo." % memory)
print memory
不幸的是,每当我实际尝试运行该东西时,我都会遇到错误,如下所示。
[<_wmi_object: \\USER-PC\root\cimv2:Win32_PerfRawData_PerfProc_Process.Name="some_program">]
instance of Win32_PerfRawData_PerfProc_Process
{
Name = "some_program";
WorkingSet = "19386368";
};
Traceback (most recent call last):
File "C:\Python26\Test scripts\Testify", line 25, in -toplevel-
memory = measureMemory()
File "C:\Python26\Test scripts\Testify", line 19, in measureMemory
print subset['WorkingSet']
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 242, in __getitem__
raise TypeError("This object does not support enumeration")
TypeError: This object does not support enumeration
我不确定为什么这会引发错误,因为我认为我没有对我从中获取代码的示例进行任何重大更改。 我正在使用Python 2.4.4,如果这很重要的话,不幸的是我无法真正升级,无论它有多大帮助。
I've recently been working on a Squish test script, and trying to do something like what's described in the solution at:
Total memory used by Python process?
The relevant snippets from my code are as follows:
def measureMemory():
w = wmi.WMI('.')
result = w.query("SELECT WorkingSet FROM Win32_PerfRawData_PerfProc_Process WHERE Name=\"some_program\"")
print result
for WorkingSet in result:
print WorkingSet
subset = result[0]
print subset['WorkingSet']
# return result[0]['WorkingSet']
for i in range(50):
memory = measureMemory()
if memory:
# test.passes("%d memory used during undo." % memory)
print memory
Unfortunately, I've run into an error whenever I actually try to run the thing, as can be seen below.
[<_wmi_object: \\USER-PC\root\cimv2:Win32_PerfRawData_PerfProc_Process.Name="some_program">]
instance of Win32_PerfRawData_PerfProc_Process
{
Name = "some_program";
WorkingSet = "19386368";
};
Traceback (most recent call last):
File "C:\Python26\Test scripts\Testify", line 25, in -toplevel-
memory = measureMemory()
File "C:\Python26\Test scripts\Testify", line 19, in measureMemory
print subset['WorkingSet']
File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 242, in __getitem__
raise TypeError("This object does not support enumeration")
TypeError: This object does not support enumeration
I'm not sure why this should be throwing an error, as I don't think I've changed anything significant from the example I took code from.
I'm using Python 2.4.4, if that's significant, and unfortunately I can't really upgrade, no matter how much it might help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WMI 语法似乎与示例有所不同。尝试使用subset.WorkingSet而不是subset['WorkingSet']
The WMI syntax seems to have changed from the examples. Try using subset.WorkingSet instead of subset['WorkingSet']