timer delays and kbhit() in Pythonwin?

Spencer Doidge spencer at spencerdoidge.com
Sat Feb 16 22:35:05 EST 2002


The following script works fine running under Windows in the console, but it
doesn't work right in Pythonwin.
The point of this script is that while we are waiting 20 seconds for the
'hello' message to be printed, we can intervene with a keystroke and cause
function doit() to terminate immediately.
I suppose it doesn't work right in Pythonwin because kbhit() is only
supported in the console. Is there a way to accomplish this same purpose
running Pythonwin?
----------------------------------------------------------
from threading import *
from msvcrt import *

def hello():
    print 'hello'

def doit():
    t=Timer(20.0,hello)
    t.start()
    done = 0
    while(done==0):
        if(kbhit()):
            done=1
            t.cancel()
            print 'cancelled'
        elif (t.finished.isSet()):
            done=1
            print 'done'
----------------------------------------------------------







More information about the Python-list mailing list