Skip to content

Instantly share code, notes, and snippets.

@jorgeas80
Last active January 27, 2020 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeas80/65bc92e689fe05ddce24438e0c5853dc to your computer and use it in GitHub Desktop.
Save jorgeas80/65bc92e689fe05ddce24438e0c5853dc to your computer and use it in GitHub Desktop.
A few useful tricks when debugging code with [i]pdb
# Put a breakpoint in a file that is not part of our code
# Ref: https://stackoverflow.com/q/13589736/593722
(Pdb) import sys
(Pdb) sys.path.append("/home/user/path/to/another/module")
(Pdb) import another_module
(Pdb) b another_module:356
Breakpoint 1 at /home/user/path/to/another/module/another_module.py:356
(Pdb) c
# Conditionally hit the breakpoint #1
(Pdb) conditions 1 some_variable == some_value
# Watch a variable when you are hitting breakpoint #1. And ensure the breakpoint is only hit whenever the variable takes a certain value.
# Ref: https://stackoverflow.com/a/34620310/593722
(Pdb) commands 1
(com) print(some_variable)
(com) end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment