Python:Windows 中的双键盘中断?
我正在 Python 3.1.2 中运行基于控制台的应用程序。我希望应用程序在提示符下捕获 Ctrl-C 并根据上下文进行处理。我按预期收到了 KeyboardInterrupt,但出乎意料的是,当我去写警告消息时,有时我会再次看到它。追溯如下。各位聪明人有什么想法吗?
Traceback (most recent call last): File "E:\Dropbox\git\vocabulary\v.py", line 58, in main command, args = c.getcommand() File "E:\Dropbox\git\vocabulary\console.py", line 81, in getcommand command, *args = input(prompt).split() KeyboardInterrupt During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\Dropbox\git\vocabulary\v.py", line 125, in main() File "E:\Dropbox\git\vocabulary\v.py", line 71, in main print("\nUse 'quit' to exit the application.") File "E:\Dropbox\git\vocabulary\utilities.py", line 191, in write self.stream.write(data) KeyboardInterrupt
I'm running a console-based app in Python 3.1.2. I want the app to trap a Ctrl-C at the prompt and handle it according to context. I'm getting the KeyboardInterrupt as expected, but unexpectedly, I'm sometimes seeing it again when I go to write a warning message. The tracebacks are below. Any thoughts from you smart people?
Traceback (most recent call last): File "E:\Dropbox\git\vocabulary\v.py", line 58, in main command, args = c.getcommand() File "E:\Dropbox\git\vocabulary\console.py", line 81, in getcommand command, *args = input(prompt).split() KeyboardInterrupt During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\Dropbox\git\vocabulary\v.py", line 125, in main() File "E:\Dropbox\git\vocabulary\v.py", line 71, in main print("\nUse 'quit' to exit the application.") File "E:\Dropbox\git\vocabulary\utilities.py", line 191, in write self.stream.write(data) KeyboardInterrupt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法重现这个。
工作正常并按预期捕获 CTRL-C。
I can't reproduce this.
Works just fine and traps CTRL-C as expected.