Debugging

Python Debugger

# insert below code to location to break into the debugger
import pdb; pdb.set_trace()

# Starting python 3.7, use below code
breakpoint()

# Passing variable in CLI
$ python3 -m pdb app.py arg1 arg2

Some Debugger commands

  • p $variable: Print value of variable

  • n (next): Continue execution until the next line in the current function is reached or it returns.

  • s (step): Execute the current line and stop at the first possible occasion (either in a function that is called or in the current function).

  • $Enter: repeat last command

  • l (list): list 11 lines of current line

  • ll (longlist): list source code of current function

  • b(reak) [ ([filename:]lineno | function) [, condition] ]: set breakpoint, just b to list all breakpoints

  • c(ontinue): continue execution until breakpoint is found

  • cl(ear) filename:lineno: delete a breakpoint

  • cl(ear) [bpnumber [bpnumber...]]: delete a breakpoint

  • enable|disable bpnumber: enable|disable breakpoint

  • tbreak: set a temporary breakpoint which is removed automatically when it’s first hit

  • a: prints the argument list of the current function.

Error

urllib only support OpenSSL1.1.1

  • The reason is urllib3 v2 require OpenSSL 1.1.1+, but it's compiled with LibreSSL 2.8.3

  • Solution: uninstall urllib and install urllib3 version less than 2

Reference

  • https://realpython.com/python-debugging-pdb/

Last updated