Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

raw_input with limited time?

Tags:

python

time

input

Is there a way to give the user a raw_input, but give a null response ("") if nothing is typed within x amount of time? I'd like to give the user 10 seconds to enter options when the script starts, but if time expires (or they press enter), simply continue the script. If you know AppleScript, I'd like display dialog "Enter options" giving up after 10 in python

like image 825
tkbx Avatar asked Mar 08 '26 12:03

tkbx


1 Answers

If you are in unix-land, you can use python's signal library and use an alarm. Otherwise, I think raw_input is totally thread-blocking.

See this answer for implementation help.

like image 133
mayhewr Avatar answered Mar 11 '26 02:03

mayhewr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!