Debugging¶
Pdb¶
pdb is the integrated (but quite unhandy) debugger
To start it at a specific code point
import pdb; pdb.set_trace()
l
to list the current code,p
to print a variable,n
for next statement,s
to step-into andb
for 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_init
andsignal_restore
, comment out all code and insertpass
To 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
winpdb
File –> 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