Last active
October 6, 2017 18:43
-
-
Save yarko/bdaa9d3178a6db03e160fdbabb3a9885 to your computer and use it in GitHub Desktop.
conditional break for ipython terminal (**Use:** `if condition: breakpoint` instead -- **don't** use this.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is for ipython interactive | |
# - you can, for example, place this in | |
# ~/.ipython/profile_default/startup | |
def breakpoint_(condition=True): | |
''' | |
in ipython: | |
- breakpoint_() <= break always | |
- breakpoint_(False) <= never break | |
- breakpoint_(condition) <= break if True | |
''' | |
# import here, to limit | |
# to this function's namespace | |
from sys import _getframe | |
from IPython.terminal import debugger | |
if condition: | |
debugger.set_trace(_getframe().f_back) | |
return debugger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Don't use this - there's no need for it.
Is just as good. Also, note:
breakpoint()
coming with PEP 553 in Python 3.7.This came via digesting @tillahoffmann post on:
ipython/ipython#9940 (comment)
combined with jupyter docs (and newer merge) here:
http://ipython.readthedocs.io/en/stable/api/generated/IPython.terminal.debugger.html