With Thomas's suggestion, I came up with this function:
import signal
def input_or_timeout(timeout):
def nothing(sig, frame): pass
signal.signal(signal.SIGALRM, nothing)
signal.alarm(timeout)
try:
raw_input()
signal.alarm(0)
except (IOError, EOFError): pass
It expects input no more than timeoutseconds.
Windows, , raw_input() getch() msvcrt.