似乎无法计时用户输入。在SmartElectron提供的链接中,该解决方案不起作用,因为一旦请求raw_input,计时器就会暂停。
迄今为止最好的解决方案是:
# Declare a mutable object so that it can be pass via referenceuser_input = [None]# spawn a new thread to wait for input def get_user_input(user_input_ref): user_input_ref[0] = raw_input("Give me some Information: ")mythread = threading.Thread(target=get_user_input, args=(user_input,))mythread.daemon = Truemythread.start()for increment in range(1, 10): time.sleep(1) if user_input[0] is not None: break
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)