Skip to content

Store Python traceback for later debugging. 🐛

License

Notifications You must be signed in to change notification settings

ploomber/debuglater

 
 

Repository files navigation

debuglater: Store Python traceback for later debugging

Code style: black

Community | Newsletter | Twitter | LinkedIn | Blog | Website | YouTube

Tip

Deploy AI apps for free on Ploomber Cloud!

  • debuglater writes the traceback object so you can use it later for debugging
  • Works with pdb, pudb, ipdb and pdbpp
  • You can use it to debug on a different machine, no need to have access to the source code

For support, feature requests, and product updates: join our community, subscribe to our newsletter or follow us on Twitter/LinkedIn.

demo

Click here to tell your friends on Twitter!

Click here to tell your friends on LinkedIn!

Installation

pip install debuglater

# for better serialization support (via dill)
pip install 'debuglater[all]'

# ..or with conda
conda install debuglater -c conda-forge

Usage

import sys
import debuglater

sys.excepthook = debuglater.excepthook_factory(__file__)

For more details and alternative usage, keep reading.

Example

# get the example
curl -O https://raw.githubusercontent.com/ploomber/debuglater/master/examples/crash.py
# crash
python crash.py

Debug:

dltr crash.dump

Upon initialization, try printing the variables x and y:

Starting pdb...
> /Users/ploomber/debuglater/examples/crash.py(5)<module>()
-> x / y
(Pdb) x
1
(Pdb) y
0
(Pdb) quit

Note: you can also use: debuglater crash.py.dump

Integration with Jupyter/IPython

Note For an integration with papermill, see ploomber-engine

Add this at the top of your notebook/script:

from debuglater import patch_ipython
patch_ipython()
# get sample notebook
curl -O https://raw.githubusercontent.com/ploomber/debuglater/master/examples/crash.ipynb

# install package to run notebooks
pip install nbclient
# run the notebook
jupyter execute crash.ipynb

Debug:

dltr jupyter.dump

Upon initialization, try printing the variables x and y:

Starting pdb...
-> x / y
(Pdb) x
1
(Pdb) y
0
(Pdb) quit

Note: you can also use: debuglater jupyter.dump

Motivation

The Ploomber team develops tools for data analysis. When data analysis code executes non-interactively (example: a daily cron job that generates a report), it becomes hard to debug since logs are often insufficient, forcing data practitioners to re-run the code from scratch, which can take a lot of time.

However, debuglater is a generic tool that can be used for any use case to facilitate post-mortem debugging.

Use cases

  • Debug long-running code (e.g., crashed Machine Learning job)
  • Debug multiprocessing code (generate one dump file for each process)

Credits

This project is a fork of Eli Finer's pydump.

Languages

  • Python 100.0%