2 from external
.inputimeout
import inputimeout
, TimeoutOccurred
5 def query_yes_no(question
='') -> bool: #https://code.activestate.com/recipes/577058/
6 """Ask a yes/no question via raw_input() and return their answer.
7 "question" is a string that is presented to the user.
8 The "answer" return value is True for "yes" or False for "no".
10 # Always return false if not in an interactive shell
11 if not sys
.stdin
.isatty():
14 valid
= {"yes": True, "y": True, "ye": True, "no": False, "n": False}
19 choice
= inputimeout(prompt
=question
, timeout
=5)
20 except TimeoutOccurred
:
21 sys
.stdout
.write("Please respond with 'yes' or 'no' (or 'y' or 'n')")