Python CTRL + C退出解释器? [英] Python CTRL+C to exit interpreter?

查看:424
本文介绍了Python CTRL + C退出解释器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 2.73

Python 2.73

为什么当我按 CTRL + C 时在笔记本电脑上显示为什么,我可以退出解释器并在桌面上按 CTRL + C 将使解释器向我发回KeyboardInterrupt消息.我该如何摆脱这个KeyboardInterrupt并回到 CTRL + C 退出!

Why is it on my laptop when I hit CTRL+C, I can exit the interpreter and on my desktop hitting CTRL+C will make the interpreter shoot back at me a KeyboardInterrupt message. How can I get rid of this KeyboardInterrupt and go back to exiting with CTRL+C!

在我的桌面上,需要输入 CTRL + Z 并按Enter退出.

On my desktop it's required to input CTRL+Z and hitting enter to exit.

我在两台计算机上都使用PowerShell.相同的64位,一个是Win7一个是Win8

I am using PowerShell on both computer. Same 64bit, one is Win7 one is Win8

推荐答案

您可以将 CTRL - C 的信号处理程序更改为退出解释器的内容:

You could change the signal handler for CTRL-C to something that exits the interpreter:

import signal
import sys
signal.signal(signal.SIGINT, lambda number, frame: sys.exit())

您可能会将代码放在一个交互式会话开始时自动运行的文件中,然后将环境变量PYTHONSTARTUP设置为该文件的名称:

You could probably put that code in a file to be run automatically when an interactive session starts, then set the environment variable PYTHONSTARTUP to the name of that file:

http://docs.python.org /3/using/cmdline.html?highlight=startup#envvar-PYTHONSTARTUP

这篇关于Python CTRL + C退出解释器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆