我最近从ipython0.10切换到了ipython0.11。在ipython0.11中,当python调试器启用时(即使用%pdb
),我只看到一小段完整的追溯,而在ipython0.10中,我看到完整的追溯。据我所知,不能从pdb命令行直接访问完整的回溯-您可以使用'u'进行浏览,但不能直接看到它。
那么,有什么办法可以显示完整的追溯?如配置参数?
或者,更有用的是,有什么方法可以让ipython仅显示捕获的异常,而不是显示在代码中捕获的位置?
编辑:示例:
In [1]: pdb
Automatic pdb calling has been turned ON
In [2]: 1/0
> <ipython-input-2-05c9758a9c21>(1)<module>()
-1 1/0
ipdb> q
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/Users/adam/<ipython-input-2-05c9758a9c21> in <module>()
----> 1 1/0
ZeroDivisionError: integer division or modulo by zero
我想看到
q
从pdb中出来之前的ZeroDivisionError。 最佳答案
您可以使用 sys.excepthook
:
import sys
def exc_hook(type, value, traceback):
print type
sys.excepthook = exc_hook
从
sys
module documentation:您也可以尝试将
--xmode
选项设置为Plain
来启动ipython从IPython reference:
这是一些示例用法。注意每个回溯的行数差异:
--xmode=Plain
:[ 19:55 jon@hozbox ~/SO/python ]$ ipython --xmode=Plain ipython-debugger-full-traceback-on-interactive-pdb.py
------------------------------------------------------------
Traceback (most recent call last):
File "ipython-debugger-full-traceback-on-interactive-pdb.py", line 2, in <module>
1 / 0
ZeroDivisionError: integer division or modulo by zero
--xmode=Context
:[ 19:55 jon@hozbox ~/SO/python ]$ ipython --xmode=Context ipython-debugger-full-traceback-on-interactive-pdb.py
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/home/jon/SO/python/ipython-debugger-full-traceback-on-interactive-pdb.py in <module>()
1
----> 2 #!/usr/bin/python
3 1 / 0
4
5
ZeroDivisionError: integer division or modulo by zero
--xmode=Verbose
:[ 19:54 jon@hozbox ~/SO/python ]$ ipython --xmode=Verbose ipython-debugger-full-traceback-on-interactive-pdb.py
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/home/jon/SO/python/ipython-debugger-full-traceback-on-interactive-pdb.py in <module>()
1
----> 2 #!/usr/bin/python
3 1 / 0
4
5
ZeroDivisionError: integer division or modulo by zero
并且不指定.py文件:
--xmode=Plain
:[ 19:55 jon@hozbox ~/SO/python ]$ ipython --xmode=Plain
In [1]: 1 / 0
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
--xmode=Context
:[ 20:03 jon@hozbox ~/SO/python ]$ ipython --xmode=Context
In [1]: 1 / 0
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/home/jon/SO/python/<ipython console> in <module>()
ZeroDivisionError: integer division or modulo by zero
--xmode=Verbose
:[ 20:01 jon@hozbox ~/SO/python ]$ ipython --xmode=Verbose
In [1]: 1 / 0
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/home/jon/SO/python/<ipython console> in <module>()
ZeroDivisionError: integer division or modulo by zero
Using the Python debugger。
关于python - ipython调试器: full traceback on interactive pdb?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7988864/