Reputation: 37
In my program I want it to await user input, while continuing the loop. because in the loop an audio clip plays (a ding sound) to remind me to manually input what I cant automate on my pc.
import audio
import time
wait_for_user = input('WAITING FOR INPUT')
while(wait_for_user != 'yes'):
wait_for_user = input('WAITING FOR INPUT')
audio(driver,'ding.mp3')
time.sleep(3)
Obviously it just stops at wait_for_user
and doesn't continue, I just can't seem to even conceive of how to go about this.
Upvotes: 0
Views: 935
Reputation: 2205
If you're on a Unix-like OS, you can use select
to wait for IO:
import select
user_input = None
while True:
time.sleep(3)
input_ready, _, _ = select.select([sys.stdin], [], [], 0)
for sender in input_ready:
if sender == sys.stdin:
user_input = input()
if user_input is None:
# play audio
else:
# user input done
break:
Upvotes: 1