[portland] Detecting System Standby on Windows

mark gross markgross at thegnar.org
Wed Jul 16 14:54:56 CEST 2008

On Tue, Jul 15, 2008 at 11:15:18PM -0700, Ron Jackson wrote:
> Judging by the number of Mac and Linux laptops at the meetings, I
> would guess that most people are not working on Windows.
> Anyway, I'm building a specialized Python USB library for
> communication class devices (which show up as com ports).
> I've run into problems when Windows goes into Standby. During the 5
> seconds or so that the Python continues to run as Windows is shutting
> down things, my library is continuing to pound on the serial port as
> it is asynchronously shutting down. This has a tendency to cause the
> win32file.ReadFile function on the port to lock up and requires a
> physical disconnect to clear.
> Is there some way to detect that Windows has started to go into
> standby before Python is halted? If I had a status function I could
> call to make sure no standby was immanent that would likely solve my
> problem.

Its been 8 years since I've done any windows work, but yes there is a
way.  Every application gets a sent a windows message when the system
is going into a lower power state.  (I don't remember what that
message is called)  To get this message you'll need a "message loop"
running in a thread or something.  Where it will just wake up when the
OS sends a message.  You can test in that loop for the WM_SUSPEND or
something like that.


> Thanks for the help!
>   -- Ron
> _______________________________________________
> Portland mailing list
> Portland at python.org
> http://mail.python.org/mailman/listinfo/portland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/portland/attachments/20080716/9bac5649/attachment.pgp>

More information about the Portland mailing list