I want to get input from console "forcefully" upon a timeout. Normally, input()
returns user-input only after the user presses Enter, and sys.stdin.read()
terminates only after it reaches EOF
. I want to retain that behavior and add a little extra something to it. Let's call this desired input function sinput()
. Upon elapsing 10 seconds of the call to sinput()
, it would automatically make the user-input from stdin
available to the program for processing even if the user hasn't pressed Enter
by then. If the user hits return before 10 seconds, though, the script runs just fine: it collects the user-input and continues. How do I implement this?
Asked
Active
Viewed 39 times
0

HERO
- 164
- 2
- 8
-
Uhm, "abruptly" probably doesn't mean what you think it means here, or you're not explaining very well what you want. It's pretty unclear as is. Please try to rephrase and/or add more explanation. – deceze Nov 09 '21 at 10:21
-
I'll try and rephrase... – HERO Nov 09 '21 at 10:27
-
https://stackoverflow.com/questions/36349275/python-expire-input-prompt-after-timeout – Gedas Miksenas Nov 09 '21 at 13:07
-
@GedasMiksenas But those codes don't make the user-input available to the program immediately after ten seconds, they still wait for the user to press `Enter` – HERO Nov 10 '21 at 02:45
-
@HERO ah you are right, sorry my bad – Gedas Miksenas Nov 10 '21 at 06:41
1 Answers
-1
Please review Sci Prog solution. I tried and it does work. python expire input prompt after timeout
For adding timeer, simply import time package and add time.sleep(5) between start() and join() lines for example for 5.

Gedas Miksenas
- 959
- 7
- 15