I needed a way to allow a raw_input() call to time out. In case it’s useful to anyone, I wrote this solution which works under Unix-like OS’s.
Simply call nonBlockingRawInput("your prompt text", n)
where n is the number of seconds you would like the prompt to wait until it times out. If it does time out, it will return with an empty string.import signal
1 | class AlarmException(Exception): |
[Edited Aug. 30, 2010 to fix a typo in the function name and generally improve formatting]
[Edited Feb 1, 2022 to add a tad more explanation, since the comments indicate people are still finding this!]