Python debugging¶
Pdb¶
Pdb can be used to set a breakpoint in a python file:
import pdb pdb.set_trace()
Be careful, to use pdb in a PyQt4 application, it is necessary to call PyQt4.QtCore.pyqtRemoveInputHook() function before the pdb breakpoint, else the debugger enters an infinite loop printing out "QCoreApplication::exec: The event loop is already running".
import pdb from PyQt4.QtCore import pyqtRemoveInputHook pyqtRemoveInputHook() pdb.set_trace()
When the breakpoint is reached, a pdb shell opens and it is possible to check the content of the variables and to execute the code step by step (type help in pdb shell to see the available commands).
Memory leaks tracking¶
a precious tool: objgraph module
import objgraph objects = objgraph.by_type('MyType') objgraph.show_backrefs(objects)