Skip to main content

Post-mortem debugging tools for Python

Project description

Pymortem: Advanced Python Debugging

PyPI Python Versions License

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:

  1. Better traceback visualization with surrounding code context
  2. Direct access to variables at each step of the stack without navigating through a separate UI
  3. Ability to execute arbitrary code within any frame's context
  4. Support for both nested exceptions and IPython/Jupyter environments

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymortem-1.0.0rc2.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymortem-1.0.0rc2-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

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

Hashes for pymortem-1.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 e52d7101caf146b7c2f5b290733e89c687b3ef12dff5324e1ee7d4df4818f84d
MD5 eb52680d5e2c2d7b604b01da662778ff
BLAKE2b-256 5dec602506c60456672c6cbc355839183bbd048affae75ba73e19d6f6282edeb

See more details on using hashes here.

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

Hashes for pymortem-1.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a3df6a984ea5d828d0c8e7e48f3fcafff56eaf838959f65f5e748e19afeea7a
MD5 7ce2d8763b1a639af1f4e9f27da6b023
BLAKE2b-256 537889573778d73f4dcb4c3fa478a8c6116ad5f54cff2237b24afbc8ce78ff8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page