小编ita*_*ita的帖子

Windows Python解释器在Ctrl + C上退出

对于我使用的大多数Python解释器,Ctrl + C都会使解释器打印出“ KeyboardInterrupt”并保持打开状态。但是,在新计算机上的最新安装中,Ctrl + C导致解释器退出,这是不希望的。

  • 设置signal.SIGINT处理程序仍然存在。
  • 没有正在运行的启动脚本可以调整行为。
  • raise KeyboardInterrupt 不退出解释器。
  • Ctrl + C上不会发出任何文本。在Ctrl + Break上,^C在退出之前发出。

如果在以下代码片段的打sn过程中按Ctrl + C,则解释器将保持打开状态。

import time

try:
    time.sleep(100)
except KeyboardInterrupt:
    pass
Run Code Online (Sandbox Code Playgroud)

环境:Windows 10上的Python 3.4.3

python windows windows-console

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

标签 统计

python ×1

windows ×1

windows-console ×1