Skip to main content

Convenience functions for the python execution stack.

Project description

I find the supplied python traceback facilities quite awkward. These functions provide convenient facilities.

Latest release 20240412:

  • stack_dump: new select parameter to pick interesting frames for the listing.
  • Provide StackSummary and FrameSummary if Python too old.

Function caller(frame_index=-3)

Return the Frame of the caller's caller. Returns None if frame_index is out of range.

Useful frame_index values:

  • -1: caller, this function
  • -2: invoker, who wants to know the caller
  • -3: the calling function of the invoker

The default from_index value is -3.

Function frames()

Return the current stack as a list of Frame objects.

Function stack_dump(f=None, indent=0, frames=None, skip=None, select=None, format_frame=None)

Recite current or supplied stack to f, default sys.stderr.

Parameters:

  • f: the output file object, default sys.stderr
  • indent: how many spaces to indent the stack lines, default 0
  • frames: the stack Frames to write, default obtained from the current stack
  • skip: the number of Frames to trim from the end of frames; if frames is None this defaults to 2 to trim the Frames for the stack_dump function and its call to frames(), otherwise the default is 0 to use the supplied Frames as is
  • select: if not None, select particular frames; if select is a str it must be present in the frame filename; otherwise select(frame) must be true

Release Log

Release 20240412:

  • stack_dump: new select parameter to pick interesting frames for the listing.
  • Provide StackSummary and FrameSummary if Python too old.

Release 20220918: caller(): return None if the frame offset is out of range.

Release 20220429: caller: return None if the stack index is out of range.

Release 20190812: stack_dump(): trim the last 2 frames from the listing by default (they are part of stack_dump's implementation).

Release 20190101:

  • _Frame: rename .functionname to .funcname; caller: turn raw frames into Frames.
  • caller(): accept optional frame_index, default -3.

Release 20160827: Add stack_dump().

Release 20150115: PyPI metadata fixups.

Release 20150111: Tag for initial PyPI release of cs.py.stack.

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

cs.py.stack-20240412.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

cs.py.stack-20240412-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file cs.py.stack-20240412.tar.gz.

File metadata

  • Download URL: cs.py.stack-20240412.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.6

File hashes

Hashes for cs.py.stack-20240412.tar.gz
Algorithm Hash digest
SHA256 aa84eab63100e375fc286626b68b3c8b4c09db101d52b6572ae98835c3c16870
MD5 1975628a586bdf5dc1d68d0cb2fe7054
BLAKE2b-256 f5038ede2fc10ea7e2573112fae8fb44c4866acd6fc0b10c0dde29920a5fc1da

See more details on using hashes here.

File details

Details for the file cs.py.stack-20240412-py3-none-any.whl.

File metadata

  • Download URL: cs.py.stack-20240412-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.6

File hashes

Hashes for cs.py.stack-20240412-py3-none-any.whl
Algorithm Hash digest
SHA256 cf1b9d706e40f4a79ba23cc7b92123a4b9e448397b76208279eeb521ddc8656c
MD5 9f325f4f3204e1187748484bc261fba9
BLAKE2b-256 3a0bde02e3753a060a987a17472dbdbf846b4168d72d9f01e5f165c50a76144c

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