SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
Python Debuggers
About these slides
These slides roughly correspond to a talk I
gave at a DC Python meetup on 2014-04-01.
During the actual talks I live-coded rather than
referring to slides, but wanted to make a
reference document for those that couldn’t
make it.
What’s a debugger?
Like a DVR for your program:
● pause at any time
● step through line by line
● inspect values
● execute code
Why do you need a debugger?
Debuggers are a powerful tool to help you
understand what your program is doing. They
are invaluable in tracking bugs, understanding
foreign code, and much more.
Print statements are not good enough
● You end up re-running your code countless
times inserting statements on random lines
● The output is unstructured and barely
intelligible
● Your codebase becomes littered with
accidentally committed debug statements
Debugging is easy!
Insert a breakpoint:
pdb.set_trace()
Start debugger after an exception:
pdb.pm() #post-mortem
PDB Commands
h(elp) - list commands or get help on a command
b(reak) - insert a breakpoint
c(ontinue) - keep running until you hit a breakpoint
s(tep) - continue until the next line executed (step into a function)
n(ext) - continue until the next line in the current function
r(eturn) - continue until the current function returns
For a full list of commands (with better explanaitons), use the help command or
consult the documentation
Upgrade to ipdb!
install: sudo pip install ipdb
usage: s/pdb/ipdb/
… and that’s it! It works very similar, but with a few
improvements:
● better context for traces
● colors
● more commands
● tab completion
Upgrade to wdb!
install: sudo pip install wdb
usage: s/pdb/wdb/
have to run the server in the background: wdb.server.py &
● Launches a browser window
○ great for situations where you don’t have access to the
terminal (like web servers) but can be used for any
program
● awesome interface (easily jump around the call stack)
● better tab completion
● can access from other machines
Making your own debugger
Extend bdb.Bdb and override the user_* functions
You can do whatever you want on function call/return,
exception, and line executed:
* write a profiler
* visualize your code execution
* make your ide smart about code usage: what functions
actually call this one when we run our code? How often is
this line executed?
My pet project
I’ve been writing a program that logs every line, function call, return, and
exception to a file with timestamps and other important metadata.
That part is working as a proof of concept (not terribly efficient)
I hope to write multiple programs that can read that output and help developers
better understand what their code is doing (what calls what, how long do things
take, visualize code coverage, step through programs after they’ve finished
running.
I hope to post an initial version of this to github very soon. If you’re interested
and want to talk, get updates, or help, please ping me on github/mattboehm or
boehm.matthew@gmail.com
Thanks! About me:
https://github.com/mattboehm
@mattboehm
Founder of the DC/NoVA Vim Meetup: http://bit.ly/dcvim
(I hope you can make it out to an event-- you’ll learn a lot no matter what your experience level)
Python/JS developer at Novetta Solutions
(I love my job-- talk to me if you’re looking for something new)
Talk to me any time about:
Vim, Python, AngularJS, Git, Linux, dvorak, mechanical/ergonomic keyboards, standing desks, meetups,
podcasts, board games, or anything else that strikes your fancy

Más contenido relacionado

La actualidad más candente

Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
VincitOy
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
Søren Lund
 

La actualidad más candente (20)

Adopting language server for apache camel feedback from a java/Eclipse plugi...
Adopting language server for apache camel  feedback from a java/Eclipse plugi...Adopting language server for apache camel  feedback from a java/Eclipse plugi...
Adopting language server for apache camel feedback from a java/Eclipse plugi...
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)
 
PHPUnit with Magento
PHPUnit with MagentoPHPUnit with Magento
PHPUnit with Magento
 
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
Improving Code Quality In Medical Software Through Code Reviews - Vincit Teat...
 
Tweakers Developers Summit 2019 - Angular for backend developers
Tweakers Developers Summit 2019 - Angular for backend developersTweakers Developers Summit 2019 - Angular for backend developers
Tweakers Developers Summit 2019 - Angular for backend developers
 
Code Quality
Code QualityCode Quality
Code Quality
 
Go language presentation
Go language presentationGo language presentation
Go language presentation
 
Building Command Line Tools with Golang
Building Command Line Tools with GolangBuilding Command Line Tools with Golang
Building Command Line Tools with Golang
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016
 
An introduction to go programming language
An introduction to go programming languageAn introduction to go programming language
An introduction to go programming language
 
Oleksii Pedorenko and Dmytro Melnychuk "DAO Project Experience"
Oleksii Pedorenko and Dmytro Melnychuk "DAO Project Experience"Oleksii Pedorenko and Dmytro Melnychuk "DAO Project Experience"
Oleksii Pedorenko and Dmytro Melnychuk "DAO Project Experience"
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
 
Introduction to Robot Framework (external)
Introduction to Robot Framework (external)Introduction to Robot Framework (external)
Introduction to Robot Framework (external)
 
From git to forge
From git to forgeFrom git to forge
From git to forge
 
Robot framework - Lord of the Rings
Robot framework - Lord of the RingsRobot framework - Lord of the Rings
Robot framework - Lord of the Rings
 
J-Spring 2018 - Angular for Java developers
J-Spring 2018 - Angular for Java developersJ-Spring 2018 - Angular for Java developers
J-Spring 2018 - Angular for Java developers
 
Code Nomads meetup June 2018 - Angular for Java developers
Code Nomads meetup June 2018 - Angular for Java developersCode Nomads meetup June 2018 - Angular for Java developers
Code Nomads meetup June 2018 - Angular for Java developers
 
OpenValue meetup July 2018 - Angular for Java developers
OpenValue meetup July 2018 - Angular for Java developersOpenValue meetup July 2018 - Angular for Java developers
OpenValue meetup July 2018 - Angular for Java developers
 
Beyond Unit Testing
Beyond Unit TestingBeyond Unit Testing
Beyond Unit Testing
 
Automation using RobotFramework for embedded device
Automation using RobotFramework for embedded deviceAutomation using RobotFramework for embedded device
Automation using RobotFramework for embedded device
 

Similar a Python debuggers slides

icebreakerwithdevops-150218112943-conversion-gate02
icebreakerwithdevops-150218112943-conversion-gate02icebreakerwithdevops-150218112943-conversion-gate02
icebreakerwithdevops-150218112943-conversion-gate02
Manohar Kumar
 
Introducing Yeoman 1.0 beta
Introducing Yeoman 1.0 betaIntroducing Yeoman 1.0 beta
Introducing Yeoman 1.0 beta
digitalzombie
 

Similar a Python debuggers slides (20)

Autotools, Design Patterns and more
Autotools, Design Patterns and moreAutotools, Design Patterns and more
Autotools, Design Patterns and more
 
Ice breaker with dev ops
Ice breaker with dev opsIce breaker with dev ops
Ice breaker with dev ops
 
icebreakerwithdevops-150218112943-conversion-gate02
icebreakerwithdevops-150218112943-conversion-gate02icebreakerwithdevops-150218112943-conversion-gate02
icebreakerwithdevops-150218112943-conversion-gate02
 
Programming tools for developers
Programming tools for developersProgramming tools for developers
Programming tools for developers
 
Using Delphi as a no code development environment
Using Delphi as a no code development environmentUsing Delphi as a no code development environment
Using Delphi as a no code development environment
 
Github developing stack
Github developing stackGithub developing stack
Github developing stack
 
The Ring programming language version 1.6 book - Part 6 of 189
The Ring programming language version 1.6 book - Part 6 of 189The Ring programming language version 1.6 book - Part 6 of 189
The Ring programming language version 1.6 book - Part 6 of 189
 
Introduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerIntroduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debugger
 
Introducing Yeoman 1.0 beta
Introducing Yeoman 1.0 betaIntroducing Yeoman 1.0 beta
Introducing Yeoman 1.0 beta
 
Frameworkless CLI app in PHP
Frameworkless CLI app in PHPFrameworkless CLI app in PHP
Frameworkless CLI app in PHP
 
What is dev ops?
What is dev ops?What is dev ops?
What is dev ops?
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
DevOps Workshop Part 1
DevOps Workshop Part 1DevOps Workshop Part 1
DevOps Workshop Part 1
 
The Ring programming language version 1.2 book - Part 4 of 84
The Ring programming language version 1.2 book - Part 4 of 84The Ring programming language version 1.2 book - Part 4 of 84
The Ring programming language version 1.2 book - Part 4 of 84
 
Golang
GolangGolang
Golang
 
Golang
GolangGolang
Golang
 
Continuous Delivery for Python Developers – PyCon Otto
Continuous Delivery for Python Developers – PyCon OttoContinuous Delivery for Python Developers – PyCon Otto
Continuous Delivery for Python Developers – PyCon Otto
 
Insight into progam execution ppt
Insight into progam execution pptInsight into progam execution ppt
Insight into progam execution ppt
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Python debuggers slides

  • 2. About these slides These slides roughly correspond to a talk I gave at a DC Python meetup on 2014-04-01. During the actual talks I live-coded rather than referring to slides, but wanted to make a reference document for those that couldn’t make it.
  • 3. What’s a debugger? Like a DVR for your program: ● pause at any time ● step through line by line ● inspect values ● execute code
  • 4. Why do you need a debugger? Debuggers are a powerful tool to help you understand what your program is doing. They are invaluable in tracking bugs, understanding foreign code, and much more.
  • 5. Print statements are not good enough ● You end up re-running your code countless times inserting statements on random lines ● The output is unstructured and barely intelligible ● Your codebase becomes littered with accidentally committed debug statements
  • 6. Debugging is easy! Insert a breakpoint: pdb.set_trace() Start debugger after an exception: pdb.pm() #post-mortem
  • 7. PDB Commands h(elp) - list commands or get help on a command b(reak) - insert a breakpoint c(ontinue) - keep running until you hit a breakpoint s(tep) - continue until the next line executed (step into a function) n(ext) - continue until the next line in the current function r(eturn) - continue until the current function returns For a full list of commands (with better explanaitons), use the help command or consult the documentation
  • 8. Upgrade to ipdb! install: sudo pip install ipdb usage: s/pdb/ipdb/ … and that’s it! It works very similar, but with a few improvements: ● better context for traces ● colors ● more commands ● tab completion
  • 9. Upgrade to wdb! install: sudo pip install wdb usage: s/pdb/wdb/ have to run the server in the background: wdb.server.py & ● Launches a browser window ○ great for situations where you don’t have access to the terminal (like web servers) but can be used for any program ● awesome interface (easily jump around the call stack) ● better tab completion ● can access from other machines
  • 10. Making your own debugger Extend bdb.Bdb and override the user_* functions You can do whatever you want on function call/return, exception, and line executed: * write a profiler * visualize your code execution * make your ide smart about code usage: what functions actually call this one when we run our code? How often is this line executed?
  • 11. My pet project I’ve been writing a program that logs every line, function call, return, and exception to a file with timestamps and other important metadata. That part is working as a proof of concept (not terribly efficient) I hope to write multiple programs that can read that output and help developers better understand what their code is doing (what calls what, how long do things take, visualize code coverage, step through programs after they’ve finished running. I hope to post an initial version of this to github very soon. If you’re interested and want to talk, get updates, or help, please ping me on github/mattboehm or boehm.matthew@gmail.com
  • 12. Thanks! About me: https://github.com/mattboehm @mattboehm Founder of the DC/NoVA Vim Meetup: http://bit.ly/dcvim (I hope you can make it out to an event-- you’ll learn a lot no matter what your experience level) Python/JS developer at Novetta Solutions (I love my job-- talk to me if you’re looking for something new) Talk to me any time about: Vim, Python, AngularJS, Git, Linux, dvorak, mechanical/ergonomic keyboards, standing desks, meetups, podcasts, board games, or anything else that strikes your fancy