我想在等待用户输入时执行一些操作: 我在考虑:
var = raw_input("what are you thinking about")
while var == None:
dosomethingwhilewaiting()
print "input is:", var
但raw_input在用户输入进入之前一直处于阻塞状态。 有什么想法吗?
答案 0 :(得分:1)
你可以使用线程。
import thread
import time
var = None
def get_input():
global var
var = raw_input("what are you thinking about")
thread.start_new_thread(get_input, ())
i = 0
while var == None:
i += 0.1
time.sleep(0.1)
print "input is:", var
print "it took you %d seconds to answer" % i