views:

162

answers:

1

I've recently been working on a Squish test script, and trying to do something like what's described in the solution at: http://stackoverflow.com/questions/938733/python-total-memory-used/938800#938800

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.

A: 

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

blz