I am having trouble making a prompt that waits only for a certain amount of time for user input.
I've ended up using threading to start a thread that waits for the input and using the main thread to try and stop the program. The multithreading works just fine, both my raw_input code and my quit() code works perfectly fine...until I throw time.sleep() into the mix to delay the quitting of the program.
It seems like something with time.sleep() makes it wait for the thread to finish; however, I have not been able to find any time.sleep alternatives. I have not been able to find any raw_input alternatives either.
import threading
import time
def ask():
print raw_input("What's up?")
def giveUp():
print "I give up!";
quit();
print "I already gave up!";
t1 = threading.Thread(target=ask);
t1.daemon = False;
t1.start()
time.sleep(0.1);
giveUp();
I expect the output "What's up" followed after a little bit by "I give up!" followed by the program quitting.