SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 
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, 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
 
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
 
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
 

Semelhante a 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
 
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, 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
 
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
 
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.
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 

Mais de 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
 

Mais de 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
 

Último

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 

Último (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 

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