1

Possible Duplicate:
raw_input and timeout

I was wondering how I can make my raw_input have a time limit.

I want something like raw_input=("What do you want?") and then if an input isn't given in less than 5 seconds, it'd print "too late"

I've been trying to read up, but it doesn't seem like anything like this is available for raw_input

Community
  • 1
  • 1
user1692517
  • 1,122
  • 4
  • 14
  • 28
  • 2
    See http://stackoverflow.com/questions/3471461/raw-input-and-timeout, it might have what you need. – paxdiablo Oct 01 '12 at 04:59
  • @paxdiablo: Does that (a) work on Windows, and (b) guarantee that you'll never get a situation where `stdin` is `read`able but not `readline`able? If so, it's probably the best solution. – abarnert Oct 01 '12 at 05:13
  • If you can't use `select`, you need some way to cancel the `raw_input`, like sending a `signal`, or using `multiprocessing` to do it in a child process and kill it, or… Other than that, you'd either need some platform-specific API or busy-waiting. – abarnert Oct 01 '12 at 05:19
  • @abarnert: (a) No idea, (b) No idea. I was just pointing the honorable gentleman to that question. Since they are identical in pretty much every fashion (neither specify Windows or otherwise, by the way), this seems a dupe. – paxdiablo Oct 01 '12 at 05:19
  • @paxdiablo: Good point. It also seems to be a dup of http://stackoverflow.com/questions/1335507/keyboard-input-with-timeout-in-python (which accepted a `signal`-based answer instead of a `select`-based one; I know that solves (b), but probably not (a)…) – abarnert Oct 01 '12 at 05:20

1 Answers1

0

Use a timer object, setting it to the required number of seconds; and just use tje timer function to display the message you want once the event object is invoked.

Kneel-Before-ZOD
  • 4,141
  • 1
  • 24
  • 26
  • If the main thread is blocked on `raw_input`, the `Timer` can't unblock it, so this doesn't really solve the problem. – abarnert Oct 01 '12 at 05:15