Latest News

Thursday, 12 February 2015

Invoking a Python debugger at any arbitrary point

Website developed/managed by prakhar thapak






















Do you find yourself occasionally wishing you could freeze a misbehaving program at an arbitrary point in time and then examining what was going on interactively?
That's exactly what the debugger is for, but sometimes it's just too much of a bother to run your program inside it, you have to set breakpoints, etc.
Well there's a really simple alternative: call the debugger from an arbitrary point in your program, like this...
import pdb; pdb.set_trace();
You can then examine the state of your program (e.g., locals, globals).
Note that many complex programs take advantage of Python's interpreted nature and go one step further by actually providing the user a way to hook into an interactive, interpreted Python environment on-demand (e.g., debugging console listening on a given port). This allows you to explore your program, usually a long living framework or daemon, from the inside while it is running.
Twisted does this, for example.

  • Assassin Survivor Comments
  • Facebook Comments

0 comments:

Post a Comment

Item Reviewed: Invoking a Python debugger at any arbitrary point Description: Rating: 5 Reviewed By: Unknown
Scroll to Top