Post-mortem debugging tools for Python
Project description
Pymortem: Advanced Python Debugging
A bit of Python black magic that lets you efficiently inspect and manipulate execution contexts after crashes, aka, post-mortem debugging.
Installation
pip install pymortem
Features
- Improved exception tracebacks with more context
- Inspect local and global variables at each frame in the exception stack
- Handle chained exceptions elegantly
- Execute code within the context of any frame in the stack
- Works in both scripts and interactive environments (including Jupyter notebooks)
Usage
Basic Exception Analysis
import pymortem
try:
# Your code that might raise an exception
result = 1 / 0
except Exception as e:
# Get a better traceback with surrounding context
traceback_message, frame_info = pymortem.extract_from_exception(e)
print(traceback_message)
# Inspect variables at a specific frame
print(frame_info[0]["locals"]) # Local variables at the first frame
Executing Code in Exception Context
import pymortem
# After an exception occurs
exception = sys.last_value # Get the last exception
_, frame_info = pymortem.extract_from_exception(exception)
# Execute code in the context of a specific frame
pymortem.execute("""
print("Variables in this context:", locals().keys())
# Fix or inspect variables
result = some_variable * 2
print("Modified result:", result)
""", frame_info[1]) # Using frame 1 as an example
Why Use Pymortem?
Traditional debugging with pdb can be cumbersome, especially in larger projects or when using Jupyter notebooks. Pymortem gives you:
- Better traceback visualization with surrounding code context
- Direct access to variables at each step of the stack without navigating through a separate UI
- Ability to execute arbitrary code within any frame's context
- Support for both nested exceptions and IPython/Jupyter environments
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymortem-1.0.0rc2.tar.gz.
File metadata
- Download URL: pymortem-1.0.0rc2.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e52d7101caf146b7c2f5b290733e89c687b3ef12dff5324e1ee7d4df4818f84d
|
|
| MD5 |
eb52680d5e2c2d7b604b01da662778ff
|
|
| BLAKE2b-256 |
5dec602506c60456672c6cbc355839183bbd048affae75ba73e19d6f6282edeb
|
File details
Details for the file pymortem-1.0.0rc2-py3-none-any.whl.
File metadata
- Download URL: pymortem-1.0.0rc2-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a3df6a984ea5d828d0c8e7e48f3fcafff56eaf838959f65f5e748e19afeea7a
|
|
| MD5 |
7ce2d8763b1a639af1f4e9f27da6b023
|
|
| BLAKE2b-256 |
537889573778d73f4dcb4c3fa478a8c6116ad5f54cff2237b24afbc8ce78ff8e
|