小编Soo*_*hin的帖子

python tty.setraw Ctrl + C不起作用(提取)

这是我的代码。

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异常不起作用。

谢谢

python getch

5
推荐指数
1
解决办法
397
查看次数

标签 统计

getch ×1

python ×1