Skip to main content

Yet another stack/session dumper utility

A "simple" library to help analyze issues post-mortem without a debugger attached.

Usage

Dumping the process state

You can use yasdu.dump() to dump the process state. Be careful:

  • Dumps like this can contain sensitive data, like passwords, authentication tokens etc. SHARE THEM WITH EXTREME CAUTION.
  • yasdu.dump will not overwrite files and will create filename.number files.
import yasdu
yasdu.dump('dump.json', 'Comment here')
# *** Created stack dump in 'dump.json' ***
# => 'dump.json'
# 'dump.json' is actual filename the dump was saved in

yasdu.dump('dump.json', 'Comment here')
# *** Created stack dump in 'dump.json.1' ***
# => 'dump.json.1'
# Since 'dump.json' already exists, the library picked 'dump.json.1'

Hooking exceptions.

The yasdu.hook() function will hook sys.excepthook and if there's an uncaught exception killing the program it will dump the process state into yasdu_autodump_[ISODATETIME].json See hook and crash example

Loading dumps

CLI tool

For the CLI IPython is recommended but not needed.

usage: yasdu [-h] -l FILE [-S] [-y]

optional arguments:
  -l FILE, --load FILE  Loads given file and starts a Python interpreter

  -S, --no-sources      Disables reading the sources from disk and showing them, useful if they have changed.
  -y                    Assume yes to all questions
  -h, --help            show this help message and exit

Example:

$ python examples/hook_and_crash.py
*** Created stack dump in 'yasdu_autodump.json' ***
Traceback (most recent call last):
  File "examples/hook_and_crash.py", line 13, in <module>
    happily_convert_some_values()
  File "examples/hook_and_crash.py", line 8, in happily_convert_some_values
    v2 = int('deadbeef')  # oh noes
ValueError: invalid literal for int() with base 10: 'deadbeef'

Let's inspect the automatic dump.

$ yasdu -l yasdu_autodump.json
Loading dump files can allow them to execute code. Do you still want to proceed? [y/N]y
Unpickled 9 objects...
Done loading data.


# exception traceback generated by the program ↓
This is an automatic dump it has been triggered by an exception:
Traceback (most recent call last):
  File "examples/hook_and_crash.py", line 13, in <module>
    happily_convert_some_values()
  File "examples/hook_and_crash.py", line 8, in happily_convert_some_values
    v2 = int('deadbeef')  # oh noes
ValueError: invalid literal for int() with base 10: 'deadbeef'

# stack data saved in the dump and sources loaded from disk
Available frames
  0. examples/hook_and_crash.py:13 happily_convert_some_values() <--  # we're here
  1. examples/hook_and_crash.py:8 v2 = int('deadbeef')  # oh noes
LoadedFrame object is available through the `_lframe` global variable

Using IPython for shell...
# [snip]

[hook_and_crash.py:13 (0)] In [1]: sources()
   import yasdu

   some_global_variable = 'testing123'


   def happily_convert_some_values():
       v1 = int('deadbeef', 16)
       v2 = int('deadbeef')  # oh noes


   if __name__ == '__main__':
       yasdu.hook()
->     happily_convert_some_values()

[hook_and_crash.py:13 (0)] In [2]: down()
Available frames
  0. examples/hook_and_crash.py:13 happily_convert_some_values()
  1. examples/hook_and_crash.py:8 v2 = int('deadbeef')  # oh noes <--

[hook_and_crash.py:13 (0)] In [3]: sources()
   import yasdu

   some_global_variable = 'testing123'


   def happily_convert_some_values():
       v1 = int('deadbeef', 16)
->     v2 = int('deadbeef')  # oh noes


   if __name__ == '__main__':
       yasdu.hook()
       happily_convert_some_values()

# variables are loaded from the dump
[hook_and_crash.py:13 (0)] In [4]: v1
Out[4]: 3735928559

[hook_and_crash.py:13 (0)] In [5]: some_global_variable
Out[5]: 'testing123'

Metadata

Release files for yasdu 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yasdu 1.0.0
File Size Uploaded
yasdu-1.0.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yasdu 1.0.0
File Interpreter ABI Platform
yasdu-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / yasdu-1.0.0.tar.gz

Download URL yasdu-1.0.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
37845bee6df769ce1ae35a5a885a50a2d6d1e5fefa06d8ef3fa14d11459bd58c
BLAKE2b-256 checksum
How to use checksums
d50e89a2b4aea44c54d463cf5cb721370edccc61cbc1e632cecae0f577c2237d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

Release files / yasdu-1.0.0-py3-none-any.whl

Download URL yasdu-1.0.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3c524e622cd9d0d31f8da5d2ac877d9e0335a57e9dc1926f04e46e57fde7220
BLAKE2b-256 checksum
How to use checksums
6b90b09c3d2b92ea83f6c9b59688b6d5f1ecefd2f48fe72ac541294038c7b9ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page