不能覆盖sys.excepthook [英] cannot override sys.excepthook

查看:167
本文介绍了不能覆盖sys.excepthook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试根据 sys.excepthook 的行为-April / 079168.htmlrel =nofollow noreferrer>食谱

I try to customize behavior of sys.excepthook as described by the recipe.

在ipython中:

:import pdb, sys, traceback
:def info(type, value, tb):
:    traceback.print_exception(type, value, tb)
:    pdb.pm()
:sys.excepthook = info
:--
>>> x[10] = 5
-------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
NameError: name 'x' is not defined
>>>

pdb.pm()叫。似乎 sys.excepthook = info 在我的python 2.5安装中不起作用。

pdb.pm() is not being called. It seems that sys.excepthook = info doesn't work in my python 2.5 installation.

推荐答案

ipython,你正在使用,而不是普通的Python交互式shell,捕获所有的异常本身,不使用sys。除了。运行它作为 ipython -pdb ,而不仅仅是 ipython ,它会在未捕获的异常时自动调用pdb,就像你正在尝试与你的除外。

ipython, which you're using instead of the normal Python interactive shell, traps all exceptions itself and does NOT use sys.excepthook. Run it as ipython -pdb instead of just ipython, and it will automatically invoke pdb upon uncaught exceptions, just as you are trying to do with your excepthook.

这篇关于不能覆盖sys.excepthook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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