SlideShare a Scribd company logo
PDB LIKE A PRO
PHILIP BAUER
@StarzelDe
pbauer
THE BASICS
PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016
The Basics
▸ l[ist]

List source code for the current file
▸ n[ext]

Continue execution until the next line
▸ s[tep] 

Execute the current line, stop at the first possible occasion
▸ r[eturn]

Continue execution until the current function returns
▸ c[ontinue]

Continue execution, only stop when a breakpoint is encountered
PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016
The Basics II
▸ w[here] 

Show stack trace. Recent frame at bottom
▸ u[p] 

Move to older frame in stack trace
▸ d[own] 

Move to newer frame in stack trace
▸ b[reakpoint] 

Set a new breakpoint. tbreak Temporary breakpoint
▸ a[rgs]

Print the argument list of the current function.
PIMP MY PDB
PIMP MY PDB
Some Enhancements
▸ pdb++
▸ ipdb
▸ bpdb
▸ pudb
▸ and…
PIMP MY PDB
pdb in python 3.2+
▸ ll | longlist

List all source code for the current function or frame.
▸ source

Try to get source code for the given object and display it.
▸ …
PIMP MY PDB
ipdb
▸ + features
▸ - dependencies
▸ - weird sqllite
▸ - need to use ``import ipdb; ipdb.set_trace()``
PIMP MY PDB
pudb
▸ + features
▸ +/- UI
▸ - need to use import pudb; pudb.set_trace()
TEXT
PIMP MY PDB
▸ it’s actually called pdbpp
▸ + features
▸ + no problematic dependencies
▸ + drop-in-replacement
▸ - needs configuration to not break readline
pdb++
DEMO PDB++
PIMP MY PDB
pdb++
▸ you’ll need a file ~/.fancycompleterrc.py
pdb++
▸ Syntax highlighting
▸ ll | longlist

List all source code for the current function or frame.
▸ track EXPRESSION
▸ display EXPRESSION
▸ source EXPRESSION
▸ obj?
▸ obj.__class__??
▸ Sticky mode
PIMP MY PDB
Give pdb++ a try!
The person you trust
PIMP MY PDB
INTROSPECTION
INTROSPECTION
python stuff you should know
▸ dir(obj) - bäh!
▸ help(obj)
▸ help(obj.__class__)
▸ pp locals()
▸ obj.__dict__
▸ obj.__class__.__dict__
▸ pp dict(obj.__class__.__dict__)
INTROSPECTION
the inspect module
▸ It’s what is used by other nice tools
▸ import inspect
▸ print inspect.getsource(obj.__class__)
▸ inspect.getmro(obj.__class__)
ADVANCED TIPS
▸ break if some condition applies
▸ very useful in loops
▸ you need it in try/except blocks (e.g. indexing)
TIPS AND TRICKS
Conditional Breakpoints
TIPS AND TRICKS
debug
▸ Call any code and step into it with a pdb in a pdb
▸ You need to step into it after calling it!
▸ (Pdb++) self.context

<Document at /Plone/startseite>

(Pdb++) debug self.context.canSetLayout()

ENTERING RECURSIVE DEBUGGER

((Pdb++)) s

--Call--

[2] >[…]/Products/CMFDynamicViewFTI/
browserdefault.py(183)canSetLayout()

((Pdb++)) ll

183 -> @security.public

184 def canSetLayout(self):

186 mtool = getToolByName(self, 'portal_membership')
DEMO DEBUG
▸ Whenever there is a traceback you end up in a pdb!
▸ try:

run_your_stuff()

except:

import pdb; pdb.set_trace()
▸ Plone: Products.PDBDebugMode
▸ Disable when migrating/reindexing
TIPS AND TRICKS
Post-Mortem Debugging
▸ Drops you in a pdb whenever a test fails or errors
▸ Zope/Plone: bin/test -D

pytest & nosetest: pytest / nosetest --pdb

unittest: need to wrap in try/except
▸ Test-Driven Debug-Driven Development
TIPS AND TRICKS
Post-Mortem Testing
▸ add a config-file ~/.pdbrc
▸ alias inspect import inspect;

print inspect.getsource(%1)
▸ alias help !print help(%1)
TIPS AND TRICKS
Customize your pdb
TEXT
Sentry
▸ Collect tracebacks from production-environments
▸ The traceback includes all arguments for all stacks
▸ OpenSource / Django
▸ github.com/getsentry/sentry
▸ Available as a service: sentry.io
▸ starzel.de is working on a DebOps/Ansible role for Sentry
SUMMARY
SUMMARY
What to take away
▸ learn the basics
▸ try pdb++
▸ learn introspection
▸ try debug callable()
▸ use post-mortem-debugging
▸ always use pretty-print
▸ use Sentry to debug errors on production
QUESTIONS
Philip Bauer
@StarzelDe
pbauer
All Fotos by Philip Bauer. Taken in Boothbay, Maine October 2016

More Related Content

What's hot

Garbage Collection
Garbage CollectionGarbage Collection
Garbage CollectionEelco Visser
 
Intoroduction of py7zr
Intoroduction of py7zrIntoroduction of py7zr
Intoroduction of py7zrHiroshi Miura
 
3. basic data structures(2)
3. basic data structures(2)3. basic data structures(2)
3. basic data structures(2)Hongjun Jang
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06Niit Care
 
Emscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsEmscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsLuka Zakrajšek
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guideArulalan T
 
Some Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTSome Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTFramgia Vietnam
 
A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)John(Qiang) Zhang
 
STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTEr. Ganesh Ram Suwal
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibMarc Gouw
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdbOwen Hsu
 

What's hot (20)

Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Introduction to cython
Introduction to cythonIntroduction to cython
Introduction to cython
 
Intoroduction of py7zr
Intoroduction of py7zrIntoroduction of py7zr
Intoroduction of py7zr
 
Note
NoteNote
Note
 
3. basic data structures(2)
3. basic data structures(2)3. basic data structures(2)
3. basic data structures(2)
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
3 rd animation
3 rd animation3 rd animation
3 rd animation
 
Maintainable go
Maintainable goMaintainable go
Maintainable go
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
 
Emscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsEmscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math ops
 
Go for Rubyists
Go for RubyistsGo for Rubyists
Go for Rubyists
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guide
 
Some Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTSome Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDT
 
A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)
 
STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LIST
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 
Pollyfills in JavaScript
Pollyfills in JavaScriptPollyfills in JavaScript
Pollyfills in JavaScript
 
ECMA Script
ECMA ScriptECMA Script
ECMA Script
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 

Similar to pdb like a pro

Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationGlobalLogic Ukraine
 
Devel::hdb debugger talk
Devel::hdb debugger talkDevel::hdb debugger talk
Devel::hdb debugger talkabrummett
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneDavid Glick
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by exampleYunWon Jeong
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Henry Schreiner
 
Lecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfLecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfssuser02936f
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbSenthilKumar Selvaraj
 
1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt1B-Introduction_to_python.ppt
1B-Introduction_to_python.pptAmritMarwaha1
 
Tools for maintaining an open source project
Tools for maintaining an open source projectTools for maintaining an open source project
Tools for maintaining an open source projectAll Things Open
 
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+Romain Dorgueil
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Romain Dorgueil
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilPôle Systematic Paris-Region
 
Python advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocksPython advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocksJohn(Qiang) Zhang
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.Mosky Liu
 

Similar to pdb like a pro (20)

Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 
Devel::hdb debugger talk
Devel::hdb debugger talkDevel::hdb debugger talk
Devel::hdb debugger talk
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Lecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfLecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdf
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt
 
Tools for maintaining an open source project
Tools for maintaining an open source projectTools for maintaining an open source project
Tools for maintaining an open source project
 
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Testing Workshop
Testing WorkshopTesting Workshop
Testing Workshop
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
 
Python advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocksPython advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocks
 
Python lecture 02
Python lecture 02Python lecture 02
Python lecture 02
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 

More from Philip Bauer

Growing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesGrowing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesPhilip Bauer
 
Migrations migrations migrations
Migrations migrations migrationsMigrations migrations migrations
Migrations migrations migrationsPhilip Bauer
 
Plone ♥︎ Python 3
Plone ♥︎ Python 3Plone ♥︎ Python 3
Plone ♥︎ Python 3Philip Bauer
 
Mosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always WantedMosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always WantedPhilip Bauer
 
Upgrade to Plone 5
Upgrade to Plone 5Upgrade to Plone 5
Upgrade to Plone 5Philip Bauer
 
Migrations, Upgrades and Relaunches
Migrations, Upgrades and RelaunchesMigrations, Upgrades and Relaunches
Migrations, Upgrades and RelaunchesPhilip Bauer
 
It's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypesIt's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypesPhilip Bauer
 
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...Philip Bauer
 
Plone-Content-Typen mit Dexterity
Plone-Content-Typen mit DexterityPlone-Content-Typen mit Dexterity
Plone-Content-Typen mit DexterityPhilip Bauer
 

More from Philip Bauer (10)

Growing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesGrowing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaises
 
Migrations migrations migrations
Migrations migrations migrationsMigrations migrations migrations
Migrations migrations migrations
 
Plone ♥︎ Python 3
Plone ♥︎ Python 3Plone ♥︎ Python 3
Plone ♥︎ Python 3
 
Mosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always WantedMosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always Wanted
 
Upgrade to Plone 5
Upgrade to Plone 5Upgrade to Plone 5
Upgrade to Plone 5
 
Migrations, Upgrades and Relaunches
Migrations, Upgrades and RelaunchesMigrations, Upgrades and Relaunches
Migrations, Upgrades and Relaunches
 
Pimp my Plone
Pimp my PlonePimp my Plone
Pimp my Plone
 
It's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypesIt's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypes
 
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
 
Plone-Content-Typen mit Dexterity
Plone-Content-Typen mit DexterityPlone-Content-Typen mit Dexterity
Plone-Content-Typen mit Dexterity
 

Recently uploaded

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024Ortus Solutions, Corp
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptxGeorgi Kodinov
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...Alluxio, Inc.
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...informapgpstrackings
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfMeon Technology
 

Recently uploaded (20)

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 

pdb like a pro

  • 1. PDB LIKE A PRO PHILIP BAUER @StarzelDe pbauer
  • 2.
  • 4. PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016 The Basics ▸ l[ist]
 List source code for the current file ▸ n[ext]
 Continue execution until the next line ▸ s[tep] 
 Execute the current line, stop at the first possible occasion ▸ r[eturn]
 Continue execution until the current function returns ▸ c[ontinue]
 Continue execution, only stop when a breakpoint is encountered
  • 5. PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016 The Basics II ▸ w[here] 
 Show stack trace. Recent frame at bottom ▸ u[p] 
 Move to older frame in stack trace ▸ d[own] 
 Move to newer frame in stack trace ▸ b[reakpoint] 
 Set a new breakpoint. tbreak Temporary breakpoint ▸ a[rgs]
 Print the argument list of the current function.
  • 7. PIMP MY PDB Some Enhancements ▸ pdb++ ▸ ipdb ▸ bpdb ▸ pudb ▸ and…
  • 8. PIMP MY PDB pdb in python 3.2+ ▸ ll | longlist
 List all source code for the current function or frame. ▸ source
 Try to get source code for the given object and display it. ▸ …
  • 9. PIMP MY PDB ipdb ▸ + features ▸ - dependencies ▸ - weird sqllite ▸ - need to use ``import ipdb; ipdb.set_trace()``
  • 10. PIMP MY PDB pudb ▸ + features ▸ +/- UI ▸ - need to use import pudb; pudb.set_trace()
  • 11. TEXT
  • 12. PIMP MY PDB ▸ it’s actually called pdbpp ▸ + features ▸ + no problematic dependencies ▸ + drop-in-replacement ▸ - needs configuration to not break readline pdb++
  • 14. PIMP MY PDB pdb++ ▸ you’ll need a file ~/.fancycompleterrc.py
  • 15. pdb++ ▸ Syntax highlighting ▸ ll | longlist
 List all source code for the current function or frame. ▸ track EXPRESSION ▸ display EXPRESSION ▸ source EXPRESSION ▸ obj? ▸ obj.__class__?? ▸ Sticky mode PIMP MY PDB
  • 16. Give pdb++ a try! The person you trust PIMP MY PDB
  • 18. INTROSPECTION python stuff you should know ▸ dir(obj) - bäh! ▸ help(obj) ▸ help(obj.__class__) ▸ pp locals() ▸ obj.__dict__ ▸ obj.__class__.__dict__ ▸ pp dict(obj.__class__.__dict__)
  • 19. INTROSPECTION the inspect module ▸ It’s what is used by other nice tools ▸ import inspect ▸ print inspect.getsource(obj.__class__) ▸ inspect.getmro(obj.__class__)
  • 21. ▸ break if some condition applies ▸ very useful in loops ▸ you need it in try/except blocks (e.g. indexing) TIPS AND TRICKS Conditional Breakpoints
  • 22. TIPS AND TRICKS debug ▸ Call any code and step into it with a pdb in a pdb ▸ You need to step into it after calling it! ▸ (Pdb++) self.context
 <Document at /Plone/startseite>
 (Pdb++) debug self.context.canSetLayout()
 ENTERING RECURSIVE DEBUGGER
 ((Pdb++)) s
 --Call--
 [2] >[…]/Products/CMFDynamicViewFTI/ browserdefault.py(183)canSetLayout()
 ((Pdb++)) ll
 183 -> @security.public
 184 def canSetLayout(self):
 186 mtool = getToolByName(self, 'portal_membership')
  • 24. ▸ Whenever there is a traceback you end up in a pdb! ▸ try:
 run_your_stuff()
 except:
 import pdb; pdb.set_trace() ▸ Plone: Products.PDBDebugMode ▸ Disable when migrating/reindexing TIPS AND TRICKS Post-Mortem Debugging
  • 25. ▸ Drops you in a pdb whenever a test fails or errors ▸ Zope/Plone: bin/test -D
 pytest & nosetest: pytest / nosetest --pdb
 unittest: need to wrap in try/except ▸ Test-Driven Debug-Driven Development TIPS AND TRICKS Post-Mortem Testing
  • 26.
  • 27. ▸ add a config-file ~/.pdbrc ▸ alias inspect import inspect;
 print inspect.getsource(%1) ▸ alias help !print help(%1) TIPS AND TRICKS Customize your pdb
  • 28. TEXT Sentry ▸ Collect tracebacks from production-environments ▸ The traceback includes all arguments for all stacks ▸ OpenSource / Django ▸ github.com/getsentry/sentry ▸ Available as a service: sentry.io ▸ starzel.de is working on a DebOps/Ansible role for Sentry
  • 30. SUMMARY What to take away ▸ learn the basics ▸ try pdb++ ▸ learn introspection ▸ try debug callable() ▸ use post-mortem-debugging ▸ always use pretty-print ▸ use Sentry to debug errors on production
  • 31. QUESTIONS Philip Bauer @StarzelDe pbauer All Fotos by Philip Bauer. Taken in Boothbay, Maine October 2016