Timeout at command prompt
tim.golden at viacom-outdoor.co.uk
Thu Jan 12 16:28:42 CET 2006
[to do with a Win32 equivalent to the SIGALRM
interruption of a raw_input]
| Is there a windows equivalent for that solution?
Nothing so straightforward. Depends how hard you want
to try. A couple of past threads on pretty much the
exact same issue offer no equivalent solution.
Any solution which I can come with involves some
sort of getch loop with more-or-less manual timeout.
Haven't examined the source for raw_input code, but
I bet it calls the underlying c-lib get-a-string routine
which probably doesn't allow for any interrupts.
Something like the following (crude but workable):
TIMEOUT_SECS = 5.0
line = ""
print "Prompt> ",
t0 = time.time ()
if time.time () - t0 > TIMEOUT_SECS:
if msvcrt.kbhit ():
k = msvcrt.getch ()
if k == "\r":
line += k
print "String was:", line
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
More information about the Python-list