Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nicole Zuckerman - The Glory of pdb's set_trace

Nicole Zuckerman - The Glory of pdb's set_trace

Everyone needs to debug code, and it can take up a non-trivial portion of our time to wait for code to complete execution and write print messages to stdout. There’s one function in particular in the python debugger (pdb) library that can give you a much clearer understanding of what’s going on in your code, much more quickly; pdb.set_ trace(). In this talk, we’ll identify the most useful things you can do when you use set trace, that can make debugging exponentially more efficient and enjoyable.

https://us.pycon.org/2017/schedule/presentation/753/

Bde70c0ba031a765ff25c19e6b7d6d23?s=128

PyCon 2017

May 21, 2017
Tweet

Transcript

  1. Debugging with pdb.set_trace() Nicole Zuckerman Clover Health @zuckerpunch

  2. What is PDB?

  3. From the docs: Or:

  4. What is this set_trace() that you’re doing a whole talk

    about?
  5. set_trace(), in action

  6. But I already have print statements. What more do I

    need?
  7. What’s so great about set_trace()? 1. Inspect contents of variables

    during real-time execution 2. Traverse call frames 3. Travel through execution order 4. Change live code during execution
  8. Code sample time

  9. Inspect contents of variables during execution

  10. Inspect contents of variables during execution Inspecting arguments of currently

    paused function:
  11. Inspect Variables continued: print/pretty print

  12. Inspect Variables continued: print/pretty print

  13. Inspect Variables continued: print/pretty print

  14. Inspect Variables continued: print/pretty print

  15. Traverse frames in call stack

  16. Traverse Call Frames

  17. Traverse Call Frames

  18. Traverse Call Frames

  19. Traverse Call Frames

  20. Traverse Call Frames

  21. Travel through execution

  22. Traveling through execution

  23. Traveling through execution

  24. Traveling through execution

  25. Where the heck am I, anyway?

  26. None
  27. List: The Fancy Parts

  28. Change live code during execution

  29. Changing live code during execution

  30. PDB-adjacent coolness: my_thing.__dict__

  31. PDB-adjacent coolness: dir(my_thing)

  32. PDB-adjacent coolness: dir(my_thing)

  33. Pdb gotchas

  34. Gotchas pdb commands versus statements

  35. Gotchas

  36. Gotchas The Enter key

  37. Bonus! Post-mortem debugging

  38. Code sample with exception-inducing bug

  39. Post-mortem at work

  40. Breakpoints

  41. Break!

  42. Break!

  43. Clear!

  44. None
  45. https://docs.python.org/2/library/pdb.html Questions