I am trying to follow a way to create a thread that is waiting for user input; if no input is entered within 10 seconds, I want the script to destroy the spawned thread and continue processing. I have a way to return input from a stream if text is entered, but I have no way to allow a timeout to kill a newly created stream.
In the example below, the closest I came. I tell the newly created thread that it is a daemon and it will exit when the main script exits. The problem I encountered is that the thread will continue to wait until the script exits or the user has added nothing.
shared_var = ['1']
def run(ref):
ref[0] = raw_input("enter something: ")
print "shared var changed to '%s'" % (ref[0])
thread = threading.Thread(target=run, args=(shared_var,))
thread.daemon = True
thread.start()
time.sleep(10)
print "shared var = " + shared_var[0]
, - ( ), , , raw_input