【问题标题】:KeyboardInterrupt in Windows?Windows中的键盘中断?
【发布时间】:2010-11-24 13:50:15
【问题描述】:

如何在 Windows 中生成 KeyboardInterrupt?

while True:
    try:
        print 'running'
    except KeyboardInterrupt:
        break

我希望 CTRL+C 停止这个程序,但它不起作用。

【问题讨论】:

  • 请说明它在哪里不起作用以及如何使用它 - 否则我们无法为您提供帮助,我们不是千里眼...... :)

标签: python windows keyboardinterrupt


【解决方案1】:

您的代码在运行到 Windows 控制台时运行正常。

Ctrl+C 生成 KeyboardInterrupt 是一个控制台功能。如果您从 SciTE 之类的文本编辑器运行它,它将无法工作。

【讨论】:

  • 没错,在 Linux 和 Windows 上从 Vim(启动控制台)运行时它运行良好。感谢您的提示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-26
  • 1970-01-01
  • 2011-05-28
  • 2020-11-22
  • 2015-08-22
  • 2014-08-11
  • 1970-01-01
相关资源
最近更新 更多