I think this is what you want...after come cleanup.  Test it on a 32 bit
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx

I can put it in my clone if that's better

def windows_memory_usage():
    """Return physical memory usage (float)
    Works on Windows platforms only"""
    from ctypes import windll
    from ctypes.wintypes import byref, Structure, DWORD, sizeof
    import ctypes
    class MemoryStatus(Structure):
        _fields_ = [('dwLength', ctypes.c_uint32), ('dwMemoryLoad',
ctypes.c_uint32),
                    ('dwlTotalPhys', ctypes.c_uint64), ('dwlAvailPhys',
ctypes.c_uint64),
                    ('dwlTotalPageFile', ctypes.c_uint64),
('dwlAvailPageFile', ctypes.c_uint64),
                    ('dwlTotalVirtual', ctypes.c_uint64),
('dwlAvailVirtual', ctypes.c_uint64),
                    ('dwlAvailExtendedVirtual', ctypes.c_uint64),]
    memorystatus = MemoryStatus()
    memorystatus.dwLength = sizeof(MemoryStatus)
    windll.kernel32.GlobalMemoryStatusEx(byref(memorystatus))
    return float(memorystatus.dwMemoryLoad)

On Tue, May 15, 2012 at 10:33 AM, Matt Anderson <[email protected]> wrote:

> Correction, calling it from spyder(a working spyder) doesn't crash.
>  Calling this function from python/ipython does cause a crash
>
>
> On Tue, May 15, 2012 at 10:29 AM, Matt Anderson <[email protected]>wrote:
>
>> However, importing the windows_memory_usage function and calling it
>> doesn't crash...mine returns 73
>>
>>
>> On Tue, May 15, 2012 at 10:28 AM, Jed Ludlow <[email protected]>wrote:
>>
>>> On Tue, May 15, 2012 at 9:24 AM, Matt Anderson <[email protected]>wrote:
>>>
>>>> Jed wins the prize,
>>>>
>>>> It looks like this function may not be any good on 64 bit systems (in
>>>> utils\system.py)
>>>>
>>>> def windows_memory_usage():
>>>>     """Return physical memory usage (float)
>>>>     Works on Windows platforms only"""
>>>>     from ctypes import windll
>>>>     from ctypes.wintypes import byref, Structure, DWORD
>>>>     class MemoryStatus(Structure):
>>>>         _fields_ = [('dwLength', DWORD), ('dwMemoryLoad', DWORD),
>>>>                     ('dwTotalPhys', DWORD), ('dwAvailPhys', DWORD),
>>>>                     ('dwTotalPageFile', DWORD), ('dwAvailPageFile',
>>>> DWORD),
>>>>                     ('dwTotalVirtual', DWORD), ('dwAvailVirtual',
>>>> DWORD),]
>>>>     memorystatus = MemoryStatus()
>>>>     windll.kernel32.GlobalMemoryStatus(byref(memorystatus))
>>>>     return float(memorystatus.dwMemoryLoad)
>>>>
>>>>
>>> Yes, running system.py as a script produces the same interpreter crash.
>>> Some days ctypes is your friend. Some days it isn't :).
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "spyder" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/spyderlib?hl=en.
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"spyder" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/spyderlib?hl=en.

Reply via email to