开发者

WMI querying issues in Python

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 __getit开发者_StackOverflow中文版em__
    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.


The WMI syntax seems to have changed from the examples. Try using subset.WorkingSet instead of subset['WorkingSet']

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜