Timeout at command prompt

Amit Khemka khemkaamit at gmail.com
Thu Jan 12 01:25:29 EST 2006


One way would be to use 'signal' s ... something like this should work

import signal
TIMEOUT = 5 # number of seconds your want for timeout
signal.signal(signal.SIGALRM, input)
signal.alarm(TIMEOUT)

def input():
 try:
   foo = raw_input()
   return foo
except:
  # timeout
  return


cheers,
amit.



On 11 Jan 2006 13:24:34 -0800, Thierry Lam <lamthierry at gmail.com> wrote:
> I can use the python function raw_input() to read any input from the
> user but how can I add a timeout so that my program exits after x
> period of time when no input has been entered.
>
> Thierry
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
----
Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.



More information about the Python-list mailing list