Last active
January 27, 2020 14:00
-
-
Save jorgeas80/65bc92e689fe05ddce24438e0c5853dc to your computer and use it in GitHub Desktop.
A few useful tricks when debugging code with [i]pdb
This file contains hidden or 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
# 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