[python-win32] Notification of standby/hibernate

Steve Freitas sflist at ihonk.com
Thu Feb 8 20:45:54 CET 2007


Hi Tim.

On Thu, 2007-02-08 at 09:33 +0000, Tim Golden wrote:
> Steve Freitas wrote:
> > Hi all,
> > 
> > I'm new to the list (and Win32 programming) and glad to be here.
> 
> Welcome to the wonderful world of Win32 in Python!

Thanks! I've been doing Python network programming on *nix for a few
years now, so it'll be nice to expand my platform experience.

> Someone asked something quite similar on c.l.py recently:
> 
> http://tinyurl.com/227f2c
> 
> The second responder does point out that the whole point
> of the suspend/hibernate operations is that the programmer
> doesn't have to do anything: his program state is saved and
> restored transparently. But I assume you know what you're
> about...

Thanks for the tip (and the TinyURL!). Yes, my service involves network
connections, and while my server and client are robust against non-sleep
outages, this will give me the chance to do a little cleanup that will
keep things tidier without waiting for keepalives to time out.

I hope you don't mind doing a little hand-holding, since I have zero
experience with Win32 and am therefore bumbling about.

I looked at this:

http://msdn2.microsoft.com/en-us/library/aa394362.aspx

Which leads me to believe that the right way to do this is somewhere
along these lines:

class MyPowerClass(object):
    def __init__(self):
        if self.EventType == 4:
            print 'suspending'
	elif self.EventType == 7:
	    print 'resuming'

DispatchWithEvents('Win32_PowerManagementEvent', MyPowerClass)

Of course that's wrong, since I expect in __init__ EventType hasn't been
set yet, but am I close?

Since this is running as a service, I'm busy doing other things in a
thread, and I want to avoid polling for status. So basically what I'm
looking for is a way to register one of my methods to be called with a
power event.

Thanks for your help so far,

Steve




More information about the Python-win32 mailing list