0

I would like to be able to time out a script in python 3 after 10 seconds or so if there hasn't been any input from the keyboard. I've researched using the signal, time, and thread modules and they are all getting complicated to me. Preferably, I would just like to use the time module being that I'm already using it and vaguely familiar with it.

Ideally, I would like it to run as follows:

>>>you have 10 seconds to type something in..

Sorry, too slow.

>>>you have 10 seconds to type something in..

HEY!! #user's input

you entered: 'HEY!!'

  • You can't do that without some kind of threading/multiprocessing, as your research should have taught you; `time` on its own will block the process, you can't have simultaneous processes. – jonrsharpe Nov 26 '14 at 21:03
  • You CAN do _SELECT_ calls etc. when reading from network with simple timeout, rather than having to have threads and polling those threads. Same is possible in "C" in read and write call. I am also searching for solution if this simple thing is possible in python. why @jonrsharpe do you are making a very harsh remark on ON by 'claiming' that it can't be done without 'multithreading'? your research seems more primitive than OP!.. Besides, I don't understand why do people downvote a straight forward question? – Dipan Mehta Aug 07 '17 at 06:39
  • Possible duplicate of [raw\_input and timeout](https://stackoverflow.com/questions/3471461/raw-input-and-timeout) – jonrsharpe Aug 07 '17 at 06:46

1 Answers1

-1

This will work, the highest answer wont run on Windows, but scroll down an answer and it will show you how to fix for Windows: raw_input and timeout

Community
  • 1
  • 1