LoginSignup
8
8

More than 5 years have passed since last update.

Pythonスクリプトを走らせたときに,エラーになったらデバッガに入ってほしいときに使うと便利な関数メモ

Last updated at Posted at 2017-04-11

pdbよりも強いIpyhoon.coreのdebuggerを使う方法です.

set_debugger.py
import sys

def set_debugger_org():
    if not sys.excepthook == sys.__excepthook__:
        from IPython.core import ultratb
        sys.excepthook = ultratb.FormattedTB(call_pdb=True)

def set_debugger_org_frc():
    from IPython.core import ultratb
    sys.excepthook = ultratb.FormattedTB(call_pdb=True)

def set_trace():
    from IPython.core.debugger import Pdb
    Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back)

としてset_debugger_org_frc()などをmain関数内で呼んであげれば良い.

うまくデバッガに入ってくれないときも残念ながらあります.

こちら先輩に教わりました.ありがとうございます.

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8