这是我的代码。
def getch():
fd = sys.stdin.fileno()
old_Settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
sys.stdin.flush()
except KeyboardInterrupt:
print ("[Error] Abnormal program termination")
finally:
termios.tcsetattr(fd,termios.TCSADRAIN,old_settings)
return ch
Run Code Online (Sandbox Code Playgroud)
在此代码中,KeyboardInterrupt异常不起作用。
谢谢