Mortuary is a dead-simple post-mortem debugging tool for Python. It provides a context manager to grab uncaught exceptions, dumps a traceback into a portable pickle format, and later allows you to attach a debugger to the traceback file.
- Dead simple: Mortuary is a single < 500 line Python file.
- No dependencies: Mortuary has no dependencies outside the standard library.
dill
andipdb
are optional dependencies. - Portable: Mortuary's dump files are portable between different versions of Python and different machines. Attach dump files to tickets to share a debugging context between developers.
Here is a script with an error in it.
import mortuary
def is_even(number):
return number % 2 == 0
def add(a, b):
return a + b
with mortuary.context():
is_even(add("1", "2"))
Running this script will raise a ValueError
and print a traceback.
Additionally Mortuary will create a traceback-dump.pkl
file.
$ python script.py
Traceback (most recent call last):
File "script.py", line 13, in <module>
is_even(add("1", "2"))
File "script.py", line 5, in is_even
return number % 2 == 0
~~~~~~~^~~
TypeError: not all arguments converted during string formatting
$ ls | grep dump.pkl
traceback-dump.pkl
Later, we can open a debugger session using the dump file
$ python -m mortuary traceback-dump.pkl
> script.py(5)is_even()
-> return number % 2 == 0
(Pdb) p number
'12'
Mortuary is distributed on PyPI and is pip-installable
pip install mortuary
Alternatively, you can simply copy the mortuary.py
file directly into your project.
mortuary
is distributed under the terms of the MIT license.
Mortuary's traceback dump is based on debuglater and pydump.