Debugging¶
Pdb¶
pdb is the integrated (but quite unhandy) debugger
To start it at a specific code point
import pdb; pdb.set_trace()
lto list the current code,pto print a variable,nfor next statement,sto step-into andbfor breakpointuse the power of
dir()to get a list of attributes of a variable / class
Pudb¶
Nice ncurses based debugger
Same keybindings as pdb
Install
pip install pudb
Afterwards edit /usr/lib/python2.6/site-packages/urwid/raw_display.py, go to
signal_initandsignal_restore, comment out all code and insertpassTo invoke pudb
import pudb; pudb.set_trace()
To start a script in pudb
python -m pudb.run yourfile.py
Winpdb¶
A graphical debugger with remote support and conditional breakpoints
To invoke it
import rpdb2; rpdb2.start_embedded_debugger("password")
Now launch
winpdbFile –> Password, File –> AttachTo tunnel winpdb through SSH
ssh -C -N -f -L 51000:localhost:51000 user@$SERVER_HOST
Inject a pudb into a running process¶
Install pyrasite
Create a inject-pudb.py file
import pudb;pudb.set_trace()
Find pid of desired python process
Inject the code
pyrasite <pid> inject-pudb.py
Connect an ipython shell to a running process¶
Install pyrasite
Create a inject-ipython.py file
from IPython.frontend.terminal.embed import InteractiveShellEmbed
ipshell = InteractiveShellEmbed()
ipshell()
Find pid of desired python process
Inject the code
pyrasite <pid> inject-ipython.py