“ctrl c,ctrl d和ctrl z都不会对执行产生任何影响.”
将这些代码行添加到程序的标题中,ctrl c将退出它.
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
如果你想在程序遇到异常时自动进入pdb调试器,只需执行以下操作:
import sys
def excepthook(type_, value, tb):
import pdb
import traceback
# print the exception...
traceback.print_exception(type_, value, tb)
# ...then start the debugger in post-mortem mode
pdb.pm()
# we are NOT in interactive mode
if not hasattr(sys, 'ps1') or sys.stderr.target.isatty():
# this stops PyQt from freezing the terminal
from PyQt4.QtCore import pyqtRemoveInputHook
pyqtRemoveInputHook()
sys.excepthook = excepthook