[Tutor] Access to Windows Timers / Idle "states"??

ak@silmarill.org ak@silmarill.org
Tue, 05 Jun 2001 20:30:50 -0400


On Wed, Jun 06, 2001 at 01:57:04AM +0200, Javier JJ wrote:
> Hi all!!
> 
> After some "lurking" on the list (and not too much time to program, either
> :-) I've decided to jump with both feet in :-)
> 
> I'm trying to make a program that can handle "timers" (ie, set a timer for
> "x" seconds later) and / or "register" itself to recieve windows events.
> 
> The idea is, when I launch this program, I want to be able to set a certain
> amount of time after whihc I want my program to do something (namely, kill
> another program :-)
> 
> At the moment, the "killing another program" would be handled with the
> pslist and pskill utils from sysinternals, so I "only" want to be able to
> set a timer...
> 
> Alternatively, I'd like to be able to "know" when the "idle" process kicks
> in, like to know when the countdown for the screensaver starts....
> 
> The thing is, I have a program that every now and then locks itself solid
> and the only way out is a hard reboot (even in W2k, ctrl-alt-del won't work,
> even though the OS "seems" to be getting the keys, and the mouse cursor
> moves). So, I'd like to be able to "sense" when the OS hasn't been getting
> any imput (keys / mouse) for a set period of time and, if that happens,
> it'll just kill the offending process....
> 
> Am I making any sense at all?

Sort of :-). I don't use windows anymore, so I can only help with the timer
thing.. the command for it is time.sleep(5) to sleep for 5 seconds. If you want
to set hours or minutes, the way to do so is this: time.sleep(60*60*3.5) for 3.5
hours, for instance. Also, you have time.time() which gives you current time in
seconds from the start of epoch (~1970). 

Anyway, in order for timer to work, here's what you can do:

sense_keypress()
time.sleep(60)
if not keypresses_happened():
    os.kill(someprog)

Look at docs for os.kill.

time.time() you can use to tell how long something took, like this:

t = time.time()
do_something()
print 'do_something() took %d seconds' % (time.time() - t)


> 
> Any and all help would be greatly appreciated.
> 
>     TIA
> 
>     Javier
> 
> ----
> 
> Hm..what's this red button fo:=/07<NO CARRIER
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Lucifer Sam Siam cat
Always sitting by your side
Always by your side
That cat's something I can't explain
        - Syd