我有监视用户的输入,看起来像这样一个主题:如何在Python 3.x中中止用户的输入?
def keyboard_monitor(temp): #temp is sys.stdin
global flag_exit
while True:
keyin = temp.readline().rstrip().lower()
if keyin == "exit":
flag_exit = True
print("Stopping...")
if flag_exit == True:
break
如果键入退出标志的设置正确,所有其他线程终止。如果我的另一个线程设置标志,则此线程拒绝完成,因为它挂在用户输入上。我必须输入一些东西才能完成。如何更改此代码,以便在外部设置标志时程序结束?
开始。 – wim
你可以试试'temp.close()'。不知道可能会有什么影响。 – meuh
它只需要跨平台或Unix或Windows? – dawg