Skip to content

Instantly share code, notes, and snippets.

@ewjoachim
Created September 14, 2015 11:06
Show Gist options
  • Save ewjoachim/234be029423d4bcef657 to your computer and use it in GitHub Desktop.
Save ewjoachim/234be029423d4bcef657 to your computer and use it in GitHub Desktop.
Debug in place
import inspect
def debug():
"""
Anywhere in the code:
debug() # opens ipython shell
"""
from IPython.terminal.embed import InteractiveShellEmbed
ipshell = InteractiveShellEmbed()
frame = inspect.currentframe().f_back
msg = 'Stopped at {0.f_code.co_filename} at line {0.f_lineno}'.format(frame)
# Go back one level!
# This is needed because the call to ipshell is inside the function debug()
ipshell(msg, stack_depth=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment