SlideShare a Scribd company logo
POST-MORTEM DEBUGGING
AND WEB DEVELOPMENT
Alessandro Molina
@__amol__
amol@turbogears.org
Who am I
● CTO @ Axant.it, mostly Python company
(with some iOS and Android)
● TurboGears2 dev team member
● Contributions to web world python libraries
○ MING MongoDB ODM
○ ToscaWidgets2
○ Formencode
Why
● Debugging is a core part of the
development process.
● You can try to prevent issues as much as
possible, but users will find new ones.
● Gathering informations to replicate issues
is required to fix them
Debugging
At least know you have an issue.
● Debugging is the “process of finding and
reducing the number of bugs”
● Users are already doing half of the work.
● When users find a bug for you, make sure
to be aware that they found it
● Log it or it will be forgotten
Log what you really need
● Log to replicate
○ Then you are able to write tests that actually verify
the issue has been solved.

● You probably want to log:
○ WSGI Environ
○ Traceback
○ Last N stack frames local variables
○ Request Headers & Body (when size permits)
Log in an useful way
● Log data in an easy to use way
○ Log request in a way it’s quick to replay it
○ Log in a computer friendly format for test units
○ Request dump is good: netcat to replay it and is
already understood by computers.

● Organize your informations
○ Use a tool to group and avoid duplicates
○ Know what got solved and what didn’t
○ Log by email, so you don’t have to check yourself
Log or...
But log in a separate thread or...
Crash Report
● Many middlewares and frameworks
provide exception reporting by email:
○ pyramid_exclog (Pyramid)
○ WebError (Pylons)
○ BackLash (TurboGears)
○ Django & Flask, framework provided

● Logging module has what you need:
Logger.exception + handlers.SMTPHandler
Ready-Made Email Reporting
● Looking for a stand-alone solution?
○ Backlash can be used by itself, not bound to
TurboGears.
○ Only dependency is “WebOb”

● Supports both Python2 and Python3
from backlash.trace_errors import EmailReporter
email_reporter = EmailReporter(smtp_server="localhost",
error_email="email@host.com",
from_address="errors@host.com")
app = backlash.TraceErrorsMiddleware(app, [email_reporter])
Try Sentry
● Gathers data and detects duplicates
● Provides “Reply Request” button
● Mark exceptions as solved to keep track
● Can log multiple events, not only
exceptions
from backlash.trace_errors.sentry import SentryReporter
sentry_reporter = SentryReporter(sentry_dsn="http://public:secret@example.com/1")
app = backlash.TraceErrorsMiddleware(app, [sentry_reporter])
Sentry
See what’s happening now
● On development and test environments
receiving errors by email is not convenient
● In case of freezes you don’t get an
exception that can be reported
● Some problems need to be
troubleshooted on the fly
Interactive Debugger
● Python provides built-in Post Mortem
debugging through pdb module
try:
return app(environ, start_response)
except:
import pdb
pdb.post_mortem()

● While it’s ready to use and works great it’s
not the most comfortable tool when
working on web development
Browser Debugger
● Many frameworks have browser debugger
○ Pyramid DebugBar
○ Werkzeug DebuggedApplication
○ TurboGears ErrorWare

● BackLash provides a stand-alone version
of the Werkzeug debugger.
import backlash
app = backlash.DebuggedApplication(app)
Werkzeug Debugger
Browser Debugger Console
●

Browser debuggers usually implement a
special URL with an interactive console
that runs in the context of the application.

● Use it to see what’s happening right now
○ for threadId, stack in sys._current_frames().items()

● Try /__console__ on Werkzeug or Backlash
Production Debugging
● In-browser debugger must be disabled on
production environments
○ Unless you are PythonAnyware you want to block
people from running code on your servers.

● So we are back again at the starting point
○ How do I debug issues that don’t provide an
exception traceback on production?
Attaching to running processes
To inspect running applications you can rely
on tools like ispyd and pyrasite that are able
to attach to a running python process

from ispyd.plugins.wsgi import
WSGIApplicationWrapper
app = WSGIApplicationWrapper(app)
ispyd
(wsgi:18630) requests
No active transactions.

(wsgi:18630) requests

==== 67 ====

thread_id = 140735076232384
start_time = Mon Apr

9 21:49:54 2012

duration = 0.013629 seconds

HTTP_HOST = 'localhost:5000'
QUERY_STRING = ''
…

File: "wsgi.py", line 19, in hello
time.sleep(0.05)
Pyrasite
Not only Debugging
● Debugging tools can also help in finding
and solving performance issues
● When a request is taking a lot of time, just
attach ipsyd and see what it’s happening
● There are specific tools that can
proactively notify you of slow requests
Dogslow
● Dogslow is a Django tool created by
Bitbucket guys to monitor slow requests
● Notifies you by email, no need to check
● Really small codebase, it’s easy to port it to
other environments
○ Upcoming BackLash version will provide a port of
dogslow for frameworks apart Django
New Relic
● Full stack tracing
○ Controllers
○ SQLAlchemy queries
○ Background Tasks
○ External Services
○ Groups informations by controller, not URL

● On-Demand profiling
○ Turn On / Off controllers profiling from remote
New Relic
Slow requests stack trace might
not be enough
Profiling
● Full profiling has a big cost, so it is usually
constrained to development environment
● If you want to profile on production,
perform sampling, don’t profile every
request
● Use a Low Overhead profiler like PLOP, not
built-in profile module.
Questions?

More Related Content

PDF
PyConUK 2014 - PostMortem Debugging and Web Development Updated
PDF
Unit Testing Lightning Components with Jasmine
PDF
Install Project INK
PDF
Test your code
PPTX
Leakcanary tool
PPTX
Common mistakes in android development
PDF
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
KEY
Know where the fire is
PyConUK 2014 - PostMortem Debugging and Web Development Updated
Unit Testing Lightning Components with Jasmine
Install Project INK
Test your code
Leakcanary tool
Common mistakes in android development
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
Know where the fire is

Viewers also liked (13)

PDF
How better sales rep onboarding can boost your topline
PPTX
Why sales readiness? And Why Now?
PDF
Sirius sales readiness 22 tips
PPTX
Putting the Ready in Business Readiness
PDF
Business Readiness Assessment & Ocm Platform
XLSX
Business Readiness Planning Checklist
PPTX
Tips for aligning business process and systems to support accurate quota and ...
PPT
Sales budget, quotas and sales territories
PDF
Sales quota
PPT
The Planning Cycle
PPTX
Sales territory and management of sales quota
PPT
Brainstorming
PDF
Sales readiness - future of predictive sales
How better sales rep onboarding can boost your topline
Why sales readiness? And Why Now?
Sirius sales readiness 22 tips
Putting the Ready in Business Readiness
Business Readiness Assessment & Ocm Platform
Business Readiness Planning Checklist
Tips for aligning business process and systems to support accurate quota and ...
Sales budget, quotas and sales territories
Sales quota
The Planning Cycle
Sales territory and management of sales quota
Brainstorming
Sales readiness - future of predictive sales
Ad

Similar to Post-Mortem Debugging and Web Development (20)

KEY
PyCon AU 2012 - Debugging Live Python Web Applications
KEY
Monitoring and Debugging your Live Applications
KEY
Cross-platform logging and analytics
PDF
Debugging Django
PDF
What the heck went wrong?
PDF
Friction Logging and Internal Advocacy, DevRel/Asia 2020
PDF
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
PDF
Code Forensics
PDF
The quality of the python ecosystem - and how we can protect it!
PPT
Faster! Faster! Accelerate your business with blazing prototypes
PDF
I broke what? Taking over maintenance on existing (well loved) projects, by B...
PDF
I broke what?!??!? Taking over maintenance on well loved projects
PPTX
The New York Times: Sustainable Systems, Powered by Python
PDF
Tips for Happier Python Debugging
PDF
Django at Scale
PDF
Debugging of (C)Python applications
PDF
PyData Texas 2015 Keynote
KEY
PHP to Python with No Regrets
PDF
How we realized SOA by Python at PyCon JP 2015
PDF
Python in Industry
PyCon AU 2012 - Debugging Live Python Web Applications
Monitoring and Debugging your Live Applications
Cross-platform logging and analytics
Debugging Django
What the heck went wrong?
Friction Logging and Internal Advocacy, DevRel/Asia 2020
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Code Forensics
The quality of the python ecosystem - and how we can protect it!
Faster! Faster! Accelerate your business with blazing prototypes
I broke what? Taking over maintenance on existing (well loved) projects, by B...
I broke what?!??!? Taking over maintenance on well loved projects
The New York Times: Sustainable Systems, Powered by Python
Tips for Happier Python Debugging
Django at Scale
Debugging of (C)Python applications
PyData Texas 2015 Keynote
PHP to Python with No Regrets
How we realized SOA by Python at PyCon JP 2015
Python in Industry
Ad

More from Alessandro Molina (16)

PDF
PyCon Ireland 2022 - PyArrow full stack.pdf
PDF
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PDF
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
PDF
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
PDF
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PDF
PyConIT6 - Messing up with pymongo for fun and profit
PDF
PyConFR 2014 - DEPOT, Story of a file.write() gone wrong
PDF
Reactive & Realtime Web Applications with TurboGears2
PDF
MongoTorino 2013 - BSON Mad Science for fun and profit
PDF
PyConUK2013 - Validated documents on MongoDB with Ming
PDF
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
PDF
EuroPython 2013 - Python3 TurboGears Training
PDF
PyGrunn2013 High Performance Web Applications with TurboGears
PDF
Rapid Prototyping with TurboGears2
PDF
TurboGears2 Pluggable Applications
PDF
From SQLAlchemy to Ming with TurboGears2
PyCon Ireland 2022 - PyArrow full stack.pdf
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - Messing up with pymongo for fun and profit
PyConFR 2014 - DEPOT, Story of a file.write() gone wrong
Reactive & Realtime Web Applications with TurboGears2
MongoTorino 2013 - BSON Mad Science for fun and profit
PyConUK2013 - Validated documents on MongoDB with Ming
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - Python3 TurboGears Training
PyGrunn2013 High Performance Web Applications with TurboGears
Rapid Prototyping with TurboGears2
TurboGears2 Pluggable Applications
From SQLAlchemy to Ming with TurboGears2

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Machine Learning_overview_presentation.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
1. Introduction to Computer Programming.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Tartificialntelligence_presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Machine Learning_overview_presentation.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
1. Introduction to Computer Programming.pptx
20250228 LYD VKU AI Blended-Learning.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation_ Review paper, used for researhc scholars
Group 1 Presentation -Planning and Decision Making .pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
NewMind AI Weekly Chronicles - August'25-Week II
Tartificialntelligence_presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
A comparative analysis of optical character recognition models for extracting...
cuic standard and advanced reporting.pdf

Post-Mortem Debugging and Web Development

  • 1. POST-MORTEM DEBUGGING AND WEB DEVELOPMENT Alessandro Molina @__amol__ [email protected]
  • 2. Who am I ● CTO @ Axant.it, mostly Python company (with some iOS and Android) ● TurboGears2 dev team member ● Contributions to web world python libraries ○ MING MongoDB ODM ○ ToscaWidgets2 ○ Formencode
  • 3. Why ● Debugging is a core part of the development process. ● You can try to prevent issues as much as possible, but users will find new ones. ● Gathering informations to replicate issues is required to fix them
  • 5. At least know you have an issue. ● Debugging is the “process of finding and reducing the number of bugs” ● Users are already doing half of the work. ● When users find a bug for you, make sure to be aware that they found it ● Log it or it will be forgotten
  • 6. Log what you really need ● Log to replicate ○ Then you are able to write tests that actually verify the issue has been solved. ● You probably want to log: ○ WSGI Environ ○ Traceback ○ Last N stack frames local variables ○ Request Headers & Body (when size permits)
  • 7. Log in an useful way ● Log data in an easy to use way ○ Log request in a way it’s quick to replay it ○ Log in a computer friendly format for test units ○ Request dump is good: netcat to replay it and is already understood by computers. ● Organize your informations ○ Use a tool to group and avoid duplicates ○ Know what got solved and what didn’t ○ Log by email, so you don’t have to check yourself
  • 9. But log in a separate thread or...
  • 10. Crash Report ● Many middlewares and frameworks provide exception reporting by email: ○ pyramid_exclog (Pyramid) ○ WebError (Pylons) ○ BackLash (TurboGears) ○ Django & Flask, framework provided ● Logging module has what you need: Logger.exception + handlers.SMTPHandler
  • 11. Ready-Made Email Reporting ● Looking for a stand-alone solution? ○ Backlash can be used by itself, not bound to TurboGears. ○ Only dependency is “WebOb” ● Supports both Python2 and Python3 from backlash.trace_errors import EmailReporter email_reporter = EmailReporter(smtp_server="localhost", error_email="[email protected]", from_address="[email protected]") app = backlash.TraceErrorsMiddleware(app, [email_reporter])
  • 12. Try Sentry ● Gathers data and detects duplicates ● Provides “Reply Request” button ● Mark exceptions as solved to keep track ● Can log multiple events, not only exceptions from backlash.trace_errors.sentry import SentryReporter sentry_reporter = SentryReporter(sentry_dsn="http://public:[email protected]/1") app = backlash.TraceErrorsMiddleware(app, [sentry_reporter])
  • 14. See what’s happening now ● On development and test environments receiving errors by email is not convenient ● In case of freezes you don’t get an exception that can be reported ● Some problems need to be troubleshooted on the fly
  • 15. Interactive Debugger ● Python provides built-in Post Mortem debugging through pdb module try: return app(environ, start_response) except: import pdb pdb.post_mortem() ● While it’s ready to use and works great it’s not the most comfortable tool when working on web development
  • 16. Browser Debugger ● Many frameworks have browser debugger ○ Pyramid DebugBar ○ Werkzeug DebuggedApplication ○ TurboGears ErrorWare ● BackLash provides a stand-alone version of the Werkzeug debugger. import backlash app = backlash.DebuggedApplication(app)
  • 18. Browser Debugger Console ● Browser debuggers usually implement a special URL with an interactive console that runs in the context of the application. ● Use it to see what’s happening right now ○ for threadId, stack in sys._current_frames().items() ● Try /__console__ on Werkzeug or Backlash
  • 19. Production Debugging ● In-browser debugger must be disabled on production environments ○ Unless you are PythonAnyware you want to block people from running code on your servers. ● So we are back again at the starting point ○ How do I debug issues that don’t provide an exception traceback on production?
  • 20. Attaching to running processes To inspect running applications you can rely on tools like ispyd and pyrasite that are able to attach to a running python process from ispyd.plugins.wsgi import WSGIApplicationWrapper app = WSGIApplicationWrapper(app)
  • 21. ispyd (wsgi:18630) requests No active transactions. (wsgi:18630) requests ==== 67 ==== thread_id = 140735076232384 start_time = Mon Apr 9 21:49:54 2012 duration = 0.013629 seconds HTTP_HOST = 'localhost:5000' QUERY_STRING = '' … File: "wsgi.py", line 19, in hello time.sleep(0.05)
  • 23. Not only Debugging ● Debugging tools can also help in finding and solving performance issues ● When a request is taking a lot of time, just attach ipsyd and see what it’s happening ● There are specific tools that can proactively notify you of slow requests
  • 24. Dogslow ● Dogslow is a Django tool created by Bitbucket guys to monitor slow requests ● Notifies you by email, no need to check ● Really small codebase, it’s easy to port it to other environments ○ Upcoming BackLash version will provide a port of dogslow for frameworks apart Django
  • 25. New Relic ● Full stack tracing ○ Controllers ○ SQLAlchemy queries ○ Background Tasks ○ External Services ○ Groups informations by controller, not URL ● On-Demand profiling ○ Turn On / Off controllers profiling from remote
  • 27. Slow requests stack trace might not be enough
  • 28. Profiling ● Full profiling has a big cost, so it is usually constrained to development environment ● If you want to profile on production, perform sampling, don’t profile every request ● Use a Low Overhead profiler like PLOP, not built-in profile module.