发生异常时,自动打开IPython

  • crash_on_ipy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import sys


class ExceptionHook:
instance = None

def __call__(self, *args, **kwargs):
if self.instance is None:
from IPython.core import ultratb
self.instance = ultratb.FormattedTB(mode='Plain',
color_scheme='Linux', call_pdb=1)
return self.instance(*args, **kwargs)

sys.excepthook = ExceptionHook()
  • crash_on_ipy.py放到项目中,在需要使用该功能的地方import crash_on_ipy

参考

  1. http://www.zhihu.com/question/21572891

留言

2014-12-04