Skip to main content

Utility for viewing stacktraces of running python processes

Project description

Utility for inspecting python stack of running process (x64 linux only)

Installation:

pip install pytb

Usage:

sudo pytb [pid]

will show you stacktrace of each python thread.

If you want to also see greenlet stacktraces, use

sudo pytb -g [pid]

this will also show you greenlets stacktraces. NOTE: in order to find all greenlets pytb looks for all gc tracked objects, so this may take a while if you have lots of objects.

Notes:

Supports viewing python2 and python3 tracebacks (it will try to guess, whether it’s 2 or 3, however you can help it by specifying -2 or -3 option)

The utility works by reading /proc/<pid>/mem (this is why sudo is needed). It uses nm and objdump for finding inner python structures in memory.

It’s also possible that python process is compiled with different flags that influence inner python’s structure fields alignment (on which pytb heavily relies) In this case you can run it with -d python-executable option where python-executable is an executable that contains debug symbols for the process you are interested in. pytb will launch gdb in this case and ask it for offsets of fields it’s interested in.

There is also a gotcha that frame->f_code->co_filename contains not an absolute path, but relative, and if your process has chdir’ed somewhere, those relative paths will become invalid (they are used when rendering stacktraces). For this situation there is --scriptdir dir argument which defaults to /proc/<pid>/cwd and serves as a root for co_filename.

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

pytb-0.0.7.tar.gz (12.7 kB view details)

Uploaded Source

File details

Details for the file pytb-0.0.7.tar.gz.

File metadata

  • Download URL: pytb-0.0.7.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytb-0.0.7.tar.gz
Algorithm Hash digest
SHA256 242a2e45db49cbdb62965b7b2bbd39975c0be393324e9699e39c1023e4e68a97
MD5 4c7274ff56bd0ca5c71b60060e3bdf2a
BLAKE2b-256 196f9e56a554873ab00e0bdf68a8107cdd6a0715d97a7a084cae35a43820e4f7

See more details on using hashes here.

Supported by

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